In this situation, using WHERE instead of IF (as @Kurt_Bremser has offered) doesn't win you much. But it can be done in a single step. One way:
data inc exl ;
set sashelp.class (where=(sex eq "M") in=inc)
sashelp.class (where=(sex ne "M"))
;
if inc then output inc ;
else output exl ;
run ;
Another way:
data inc exl ;
do until (z_inc) ;
set sashelp.class (where=(sex eq "M")) end = z_inc ;
output inc ;
end ;
do until (z_exc) ;
set sashelp.class (where=(sex ne "M")) end = z_exc ;
output exl ;
end ;
run ;
I wouldn't recommend either because in both cases you end up reading all input records into the buffer, which defies the purpose of using WHERE vs IF in the first place.
Kind regards
Paul D.
@David_Billa Mind that all solutions relying on WHERE involve multiple reads of the input dataset and need considerably more code than the simple if, so they are inefficient both in use of computing resources and programmer's time.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.