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 (January 2000, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 14 Jan 2000 18:46:31 GMT
Reply-To:     silver0514@MY-DEJA.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         silver0514@MY-DEJA.COM
Organization: Deja.com - Before you buy.
Subject:      Re: number of records in a dataset

Here is a macro that will do what I believe that you want. Hope this helps - Steve

%**********************************************************************; %* THIS MACRO COUNTS THE NUMBER OF OBSERVATIONS IN A SAS DATASET *; %* TWO PARAMETERS ARE USED: DSN - THE SAS DATASET NAME AND NUMVAR - *; %* THE MACRO VARIABLE NAME THAT WILL CONTAIN THE OBSERVATION COUNT *; %* EXAMPLE: %NUMOBS(DSN=PREV, NUMVAR=PCNT) *; %* *; %* THIS MACRO MUST BE USED OUTSIDE OF A DATA STEP. *; % **********************************************************************; %MACRO NUMOBS(DSN=, NUMVAR=); %GLOBAL &NUMVAR; DATA _NULL_; IF 0 /*THIS IS NEVER TRUE THUS SET IS*/ THEN SET &DSN NOBS=COUNT; /*NEVER EXECUTED */ CALL SYMPUT("&NUMVAR", LEFT(PUT(COUNT,8.))); STOP; RUN; %MEND NUMOBS;

In article <FBCA978D5476D211AC4A08002BB9109802FDC2B3@ukz023.ggr.co.uk>, "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)= >

Sent via Deja.com http://www.deja.com/ Before you buy.


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