Date: Tue, 16 Nov 1999 11:18:29 -0500
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Laurie Abell <laurie_abell@DOFASCO.CA>
Subject: Re: Number of obs in dataset
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
%let id_num = %sysfunc(open(dsname));
%let numobs = %sysfunc(attrn(&id_num,nobs));
%let clz_dsn = %sysfunc(close(&id_num));
hope this helps !
> -----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
> 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
> 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);
> I know this looks pretty simple, and when I test only this (presuming
> 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...