|
Hi Jim,
if you don't believe it, just try the following code:
data somedata;
a=0;
stop;
run;
%let maybe=*;
data _null_;
set somedata;
call symput("maybe"," ");
if _n_=1 then stop;
run;
%put &maybe;
somedata exists, but has 0 obs. In this case the data-step
does NOT execute at all! This might be a problem with some
CALL SYMPUTs in it: the macro variable is never set! Even worse:
the macro variable has an old (wrong) value.
Jim Groeneveld <J.Groeneveld@ITGroups.com> on 01.02.2000 11:02:47
An: DeTeCSM HellriegelG/D/ExternalStaff/WLB@WLB
Kopie: SAS-L@LISTSERV.UGA.EDU
Thema: RE: is there such a thing as "if dataset not empty then..."?
Gerhard,
I don't think the code just below works all right. IMHO the macro variable
Maybe always becomes a space, which is not as intended. IF 'somedata'
exists, but does not contain records, CALL SYMPUT is always executed. Only
if 'somedata' does not exist the remainder of the data step is skipped.
%let maybe=*;
data _null_;
set somedata;
call symput("maybe"," ");
if _n_=1 then stop;
run;
An alternative solution than already presented (and based on solutions being
posted only recently on SAS-L) would be:
%let Maybe = * ; * Initialize;
DATA _NULL_;
IF NOBS GT 0 THEN CALL SYMPUT('MAYBE',' ');
ELSE CALL SYMPUT('MAYBE','*'); * added closing
parenthesis;
STOP;
if 0 then SET SOMEDATA NOBS=NOBS;
RUN;
&maybe PROC PRINT DATA=SOMEDATA;RUN; * "run" is always executed;
The added 'if 0 then' above prevents actually reading the data at run time,
which is not necessary as NOBS already gets determined at compilation time.
But probably the STOP prevents executing the SET at run time as well.
The initialization has been added in order to create and assign Maybe a
default value, because, if 'somedata' does not exist, NOBS can not be
determined and Maybe gets not assigned one or the other way (SYMPUT does not
execute at all in both instances).
This algorithm, as far as I remember, does not seem to work correctly with
views. NOBS would be assigned some largest (4- or 8-byte) integer value, or
otherwise, depending on the host system. Possibly removing the 'if 0 then'
allows for valid processing of views, but I'm not sure.
Have a look at the similar discussion going on about 1 or 2 months ago.
Regards - Jim.
--
Y. (Jim) Groeneveld, MSc IMRO TRAMARKO tel. +31 412 407 070
senior statistician, P.O. Box 1 fax. +31 412 407 080
head IT department 5350 AA BERGHEM IMRO TRAMARKO: a CRO
J.Groeneveld@ITGroups.com the Netherlands in clinical research
My computer now is used long enough to the year ²°°° trap.
> -----Original Message-----
> From: Gehard Hellriegel [SMTP:detecsm_hellriegelg@WESTLB.DE]
> Sent: Tuesday, February 01, 2000 10:22 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: is there such a thing as "if dataset not empty then...."?
>
> Maybe that will not run ok, because the data-step will not run, or it is
> not of
> type DATA, or it has deleted obs...
>
> %let maybe=*;
> data _null_;
> set somedata;
> call symput("maybe"," ");
> if _n_=1 then stop;
> run;
>
> "Berryhill, Tim" <TWB2@PGE.COM> on 31.01.2000 23:38:52
>
> Bitte antworten an "Berryhill, Tim" <TWB2@PGE.COM>
>
> An: SAS-L@LISTSERV.UGA.EDU
> Kopie: (Blindkopie: DeTeCSM HellriegelG/D/ExternalStaff/WLB)
> Thema: Re: is there such a thing as "if dataset not empty then..."?
>
> DATA _NULL_;
> IF NOBS GT 0 THEN CALL SYMPUT('MAYBE',' ');
> ELSE CALL SYMPUT('MAYBE','*';
> STOP;
> SET SOMEDATA NOBS=NOBS;
> RUN;
>
> &maybe PROC PRINT DATA=SOMEDATA;RUN;
>
> > ----------
> > From: Andrea Wainwright[SMTP:andrea.wainwright@CAPITALONE.COM]
> > Reply To: andrea.wainwright@CAPITALONE.COM
> > Sent: Monday, January 31, 2000 2:10 PM
> > To: SAS-L@LISTSERV.UGA.EDU
> > Subject: is there such a thing as "if dataset not empty then...."?
> >
> > I would like to check to see if a dataset contains any obs and run
> a
> > proc print if it does, otherwise I just want to skip it.
> >
> > What are some of the possible ways of accomplishing this?
> >
> > TIA
> >
> > Andrea Wainwright
>
> Mit freundlichen Gruessen
>
> DeTeCSM, Gerhard Hellriegel
>
> WestLB
> Abteilung: 001-80622
> Aderstr. 22
> D - 40217 Duesseldorf
> Tel.: +49211 826 6173
> Fax: +49211 826 5393
Mit freundlichen Gruessen
DeTeCSM, Gerhard Hellriegel
WestLB
Abteilung: 001-80622
Aderstr. 22
D - 40217 Duesseldorf
Tel.: +49211 826 6173
Fax: +49211 826 5393
|