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 (November 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 16 Nov 1999 18:20:49 +0100
Reply-To:     peter.crawford@DB.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@DB.COM>
Subject:      Re: Number of obs in dataset
Content-type: text/plain; charset=us-ascii

hmm the only time a nobs=0 situation would execute the original call symput(), is where the "dsname" is a view (or one of those strange situations which can't update the dataset header after the last obs is written like with tape storage) -=- but in that situation there may as well be a test to set that value to "unknown" or missing-but-non-zero DATA _NULL_; CALL SYMPUT('NOBS', NOBS ); SET DSNAME NOBS=NOBS; if not nobs then CALL SYMPUT('NOBS', '-1' ); STOP; RUN; Can anyone suggest a better value to indicate unknown, that won't upset the macro processor because it contains a nonnumeric "." ?

If I go on too much, stop reading !

Better than supplying something like -1, it would be a neat point to call-execute the code to count the actual obs (faster than a data step can) DATA _NULL_; CALL SYMPUT('NOBS', NOBS ); SET DSNAME NOBS=NOBS; if not nobs then do; call execute(' proc sql noprint; count(*) into ' ) ; call execute(' :nobs from &dsname; quit; ' ) ; end; STOP; RUN; You need a different approach when you only want a positive test that there are any obs. (E.G. to produce a "nill returns" statement when proc "something" report says nothing for empty input datasets.)

Where a data set may be updated in place by AF apps or SAS/FSP or data step MODIFY, or SQL delete, then the NOBS value may get confusing. NLOBS should allow for deleted obs. This is not available on a set statement. It is accessible through either ATTRN(dsid, 'NLOBS') or = (NOBS - DELOBS) from dictionary.tables.

Definitive "best solutions" need a better definition of the big picture !

So what's the best solution ?

Datum: 16.11.99 17:46 An: SAS-L@listserv.uga.edu

Antwort an: TWB2@pge.com

Betreff: Re: Number of obs in dataset Nachrichtentext:

Uhm, if DSNAME has zero observations, then the data step stops when the SET statement executes, and the CALL SYMPUT never executes. In that case, you probably get a value of 1 from some previous call. Reverse the SET and CALL statements. It is curious, but the nobs= option applies even if the statement never executes. To be cute, I sometimes code this as DATA _NULL_; CALL SYMPUT('NOBS',NOBS); STOP; SET DSNAME NOBS=NOBS; RUN;

Tim Berryhill - Contract Programmer and General Wizard TWB2@PGE.COM or http://www.aartwolf.com/twb.html Frequently at Pacific Gas & Electric Co., San Francisco The correlation coefficient between their views and my postings is slightly less than 0

> ---------- > From: Jacques Thibault[SMTP:JacquesT@IPRONLINE.COM] > Reply To: Jacques Thibault > Sent: Tuesday, November 16, 1999 8:00 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Number of obs in dataset > <SNIP> > ... > data _null_; > set dsname nobs=n; > call symput('nbobs',n); > stop; > run; > > I know this looks pretty simple, and when I test only this (presuming > dsname > has 0 obs.), it works. But when including the same lines in my macro, it > doesn't work anymore. Is anyone got this problem before? Is there any > other way to get the number of obs. (like in SQL...)?... > > Thanks for helping... >


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