Date: Tue, 16 Nov 1999 08:30:51 -0800
Reply-To: "Terjeson, Mark" <TERJEMW@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TERJEMW@DSHS.WA.GOV>
Subject: Re: Number of obs in dataset
Content-Type: text/plain
Hi Jacques,
There are 3 or 4 ways to grab the nobs. Sometimes
you want to test to see of the file exists, and sometimes
you need to check if it exists-but-has-zero-records.
Here is one of probably many different methods. The
suggestive code below does work, we use it all the time,
but the names have been changed to protect the innocent.
Sorry for the old saying, but you will have to replace the
mylib, myfile, yourpath with your own names. However, no
warrentees, etc. come with this code. It's too bad we
have to add all this legal mumbo-jumbo lately, since this
submission is suggestive with a helpful heart only.
Anyway, there are pitfalls of checking each independently
and benefits of being combined, so testing the resulting macro
variable will have tested for existence and exists-but-zero-obs
conditions.
* the routine below assumes a libref is active ;
libname mylib 'yourpath';
* test to see if dataset exists ;
* or exists with 0 observations ;
proc sql noprint;
select min(nobs,count(*)) into :m_exists
from sashelp.vtable
where libname eq upcase("mylib")
and memname eq upcase("myfile");
quit; %put m_exists is &m_exists;
you may now use if or %if to test for &m_exist gt 0
HTH,
Mark Terjeson
Washington State Department of Social and Health Services
Division of Research and Data Analysis (RDA)
(360) 902-0741
(360) 902-0705 fax
mailto:terjemw@dshs.wa.gov
> -----Original Message-----
> From: Jacques Thibault [SMTP:JacquesT@IPRONLINE.COM]
> Sent: Tuesday, November 16, 1999 8: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...
|