LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2007, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 30 Mar 2007 10:14:29 -0700
Reply-To:   SAS-Programmer@wywh.com
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Jeff J. Voeller" <SAS-Programmer@WYWH.COM>
Subject:   Re: Forcing SAS data step to execute at least one time, even if empty
Comments:   cc: drh4@PSU.EDU
Content-Type:   text/plain;charset=iso-8859-1

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;


Back to: Top of message | Previous page | Main SAS-L page