07-31-2015 09:16 AM
I have seen a data step that looks something like this:
set data old end=eod;
if eod and _n_=1 then do :
What it is trying to do is output something (line saying "No observations") if there are no observations for a specific ID. However I am having some troubles with it and i am trying to understand more of exactly what it is that it's doing, particularly what the end=eod and the eod and _n_=1 mean.
07-31-2015 09:30 AM
Yes but it needs to come before the SET otherwise then there are 0 observations it will never be executed.
You can look at the documentation for the set statement for explanation of SET statement option END.
07-31-2015 10:09 AM
If you want to check observations counts, then you could query the sashelp table:
create table HAVE (avar char(20),anum num);
set sashelp.vtable (where=(libname="WORK" and memname="HAVE" and nobs=0)); /* I.e. only get records if the dataset has zero observations */
call execute('data have; avar="No observations"; run;');
/* The above line will only be run if there is a record returned for zero observations, then the extra datastep will be generated */
Alternatively you could do:
set sashelp.vtable (where=(libname="WORK" and memname="HAVE" and nobs=0));
and then use &NOBS. in a macro.
07-31-2015 11:20 AM
For a simple "NO DATA" check, finding the actual number of observations is not necessary.