As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

BY Statement with No Variables

From sasCommunity
Jump to: navigation, search

In most cases, a BY statement with no variables is simply ignored. There is nothing in the log to report the circumstance.

For example (using SAS 9.1.3 SP4), the two steps which follow behave as if the BY statements simply were not there.

data _null_;
set sashelp.class;
proc print data=sashelp.class;

This behavior can be considered a feature in that it simplifies macro development. A caveat is that a DATA step MERGE might best be generalized not by ignoring an "empty" BY statement, but rather by introducing an invariant phantom BY variable.

The behavior appears to be undocumented. In the SAS 9.2 documentation, the syntax skeleton for the BY statement is

BY <DESCENDING> variable-1 

The absence of a pointy-bracket container around "variable-1" implies that this variable is mandatory.

PROC SORT is (very reasonably) an exception. Omitting BY variables there triggers an ERROR.

A quick poll on SAS-L (12 May 2008 thread "Empty BY Statements") suggests that the general tolerance of "BY;" has long been the behavior of SAS.

Q: Are there contexts other than PROC SORT where the BY statement must include at least one variable?

Some other statements behave the same way as the BY statement when variables do not appear. Others behave differently. So Empty Variable Lists appears to be a broader subject.