|
Am little trick in this case: if you have a read SAS dataset (no VIEW) with no
where/if clause, you should add a stop - statement in the data _null_ - step.
With some obs you will not see much difference, with a few millions, you will!
Meredith Clark <clarkmeredith@YAHOO.COM> on 10.01.2000 21:16:29
Bitte antworten an Meredith Clark <clarkmeredith@YAHOO.COM>
An: SAS-L@LISTSERV.UGA.EDU
Kopie: (Blindkopie: DeTeCSM HellriegelG/D/ExternalStaff/WLB)
Thema: Re: number of records in a dataset
I found this simple issue to be very tricky. The way
to make this work is doing something based on a macro
variable not getting initialized when the data set is
empty.
%LET FOBS=0;%*INITIALIZE FOBS PER RON FEHD;
data _null_;
set clntparm.&varx nobs=n;
call symput('FOBS','1'); %*THIS LINE
EXECUTES ONLY AFTER A READ - IF THE DATA
SET DOES NOT EXIST, THEN FOBS WOULD NOT BE
CREATED;
run;
%if NOT &FOBS %then %do;
proc datasets library=clntparm;
delete &VAR;
run;
%end;
--- "Degroot, Alain" <ad83254@GLAXOWELLCOME.CO.UK>
wrote:
> I want a macro variable RECN to contain the number
> of records in a dataset.
> It works fine when the dataset has 1 or more obs,
> not when the dataset has 0 obs.
>
> What do I need to add in the data step to result a
> zero value in the last case ?
>
> I believe there is a simple way to do this.
> Please help. Thanks.
>
>
> data a;
> tmt='AAA'; output;
> tmt='BBB'; output;
> tmt='CCC'; output;
> run;
>
> NOTE: The data set WORK.A has 3 observations and 1
> variables.
>
> data b;
> set a;
> *if tmt in ('BBB','CCC');
> if tmt in ('DDD','EEE');
> run;
>
> NOTE: The data set WORK.B has 0 observations and 1
> variables.
>
> %let recn=;
> data _null_;
> set b end=eof;
> call symput('mem'||left(put(_n_,3.),tmt);
> if eof then call
> symput('recn',left(put(_n_,best.)));
> run;
>
> %put (RECN)=&recn;
> (RECN)=
>
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
Mit freundlichen Gruessen
DeTeCSM, Gerhard Hellriegel
WestLB
Abteilung: 001-80622
Aderstr. 22
D - 40217 Duesseldorf
Tel.: +49211 826 6173
Fax: +49211 826 5393
|