Search code examples
sas

What is the difference between where and where also statement in SAS?


Very coincidentally, I find there is a where also statement in SAS.

data test;
  set sashelp.class;
  where age>13;
  where also sex='M';
run;

When I submit this, the log window shows:

NOTE: WHERE clause has been augmented.
NOTE: There were 5 observations read from the data set SASHELP.CLASS.
      WHERE (age>13) and (sex='M');

If I directly cat multiple condition by and and put them in one where statement:

data test;
  set sashelp.class;
  where age>13 and sex='M';
run;

The log window shows:

NOTE: There were 5 observations read from the data set SASHELP.CLASS.
      WHERE (age>13) and (sex='M');

So here are my questions:

  1. What is the difference between where also statement and where statement consisted with multiple conditions?
  2. If where also statement can be exactly replaced by where statement, why SAS designed where also statement?

Solution

  • There is no difference between where also and where statement with multiple conditions.

    The benefit of using where also would be the ease of commenting out only one condition? Maybe better readability of the code? It's not the only case in SAS where you can do the exact same thing with different syntax.