Date: Thu, 11 Apr 2002 16:21:55 -0400
Reply-To: don.henderson@US.PWCGLOBAL.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Don Henderson <don.henderson@US.PWCGLOBAL.COM>
Subject: Re: Proc report Assistance
Content-type: text/plain; charset=us-ascii
All of the answers that have been posted so far have answered the question
by getting the number of observations. This can be problematic at times
(e.g., the nobs option won't work for a view).
If the issue is whether the data set has any observations or not, that can
be more directly answered by using a snippet of code like:
%let haveobs = 0;
data _null_;
set <INSERT DATA SET NAME HERE>;
call symput('HAVEOBS','1');
stop;
run;
the macro variable haveobs, being binary, can then be used as follows:
%if &haveobs %then [insert action here]
And, this could further be packaged as a macro if desired.
The results of the code above are illustrated in the following sas log:
24 data obs;
25 x=1;
26 output;
27 run;
NOTE: The data set WORK.OBS has 1 observations and 1 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds
28 data noobs;
29 x=1;
30 stop;
31 run;
NOTE: The data set WORK.NOOBS has 0 observations and 1 variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds
32
33 %let haveobs = 0;
34 data _null_;
35 set obs;
36 call symput('HAVEOBS','1');
37 stop;
38 run;
NOTE: There were 1 observations read from the data set WORK.OBS.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds
39 %put haveobs = &haveobs;
haveobs = 1
40
41
42 %let haveobs = 0;
43 data _null_;
44 set noobs;
45 call symput('HAVEOBS','1');
46 stop;
47 run;
NOTE: There were 0 observations read from the data set WORK.NOOBS.
NOTE: DATA statement used:
real time 0.00 seconds
cpu time 0.00 seconds
48 %put haveobs = &haveobs;
haveobs = 0
Don Henderson
"Bob Burnham" <robert.a.burnham@DARTMOUTH.EDU> wrote in message news:
<m2it6y2f6e.fsf@dartmouth.edu>...
> >>>>> "Jim" == Jim McMillen <jimcmi2@QWEST.COM> writes:
>
> Jim> Does anyone know how to determine if there was no data
> Jim> returned and specify a different TITLE based on the fact
> Jim> that nothing was returned.
>
> Hi Jim,
>
> I don't know if this is the best way, but this is my old stand-by.
> My first step is store the number of observations in the data set in
> a macro variable -- something like this:
>
> data _null_;
> set test nobs=count;
> call symput('nobs', count);
> stop;
> run;
>
> Now I have a macro variable, &NOBS, with the number of records.
>
> To use this, I wrap my report code in a macro so that I can use some
> simple logic like this:
>
> %if &nobs = 0 %then %do;
> /* do stuff for empty data set */
> %end;
> %else %do;
> /* produce my usual report */
> %end;
>
> I'd be interested to know if anyone has other solutions that work
> well for them.
>
> P.S. I'm going to SUGI this year, so please stop me if you see me.
> I'm looking forward to finally getting to know some faces this year.
>
> Best regards to the list,
>
>
> Bob
>
> --
> Bob Burnham
> robert.a.burnham@dartmouth.edu
> http://www.dartmouth.edu/~bburnham
>
----------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.