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 11:18:29 -0500
Reply-To:     laurie_abell@DOFASCO.CA
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Laurie Abell <laurie_abell@DOFASCO.CA>
Subject:      Re: Number of obs in dataset
Comments: To: JacquesT@IPRONLINE.COM
Content-Type: text/plain

Here's an example of how you can create a macro variable (&numobs) that contains the number of observations in a SAS dataset without using a data step (courtesy of Paul Gorrell)....

An efficient way to get the number of obs in a SAS dataset is as follows:

%let id_num = %sysfunc(open(dsname)); %let numobs = %sysfunc(attrn(&id_num,nobs)); %let clz_dsn = %sysfunc(close(&id_num));

hope this helps !

Laurie

> -----Original Message----- > From: Jacques Thibault [SMTP:JacquesT@IPRONLINE.COM] > Sent: Tuesday, November 16, 1999 11:01 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Number of obs in dataset > > Hi SAS-Ls, > > I have this problem that when I wanna count the number of observations in > a > dataset and the dataset is empty, instead of having zero (0), I have one > (1). Then I red that with NOBS= , for certain SAS views, the SAS system > cannot determine the number of observations. In these cases, the SAS > system > sets the value of the NOBS= variable to the largest positive integer value > available on the host system (which means 1...) <Rf.SAS Language p.485>. > > This is my "simple" code: > > ... > 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