|
On Friday, March 30, 2007 at 8:54 a.m.
Daryl Hoffman wrote:
> I have not used SAS in a few years, but is there a way to check to
> see if there are 0 observations and still allow the datastep to
> generate a file indicating the condition?
I found myself needing to do something like this often enough that I
finally wrote a macro to take care of it. The macro is somewhat awkward,
yet still manages to be gracelessly clumsy:
%macro vbzerobs(dset,message,bgcolor,fgcolor);
/*--------------------------------------------------------------------*
| 05-23-2005: This macro prints NONE FOUND if the input |
| dataset is empty. |
| 07-19-2005: Changed to use PROC REPORT with a dummy dataset |
| for nicer formatting when using HTML output. |
*---------------------------------------------------------------------*/
%if &message= %then %let message=NONE FOUND;
%if &bgcolor= %then %let bgcolor=CCFFCC;
%if &fgcolor= %then %let fgcolor=000000;
data _null_;
if nobslorino=0 then do;
datey=compress('D'||put(today(),yymmdd10.)
||'T'||compress(put(time(),time8.),': '),'- ');
call execute('data work.'||datey||';');
call execute('dummyvar='||quote(datey)||';');
call execute('run;');
call execute('proc report data=work.'
||datey
||' nowindows noheader;');
call execute('column message;');
call execute('define message / computed color=red');
call execute("style={background=#&bgcolor foreground=#&fgcolor"
||' font_weight=bold};');
call execute('compute message / character length=76;');
call execute('message="'||"&message"||'";');
call execute('endcomp;');
call execute('run;');
call execute('proc sql;');
call execute('drop table work.'||datey||';');
call execute('quit;');
end;
set &dset nobs=nobslorino;
run;
%mend vbzerobs;
|