| Date: | Thu, 3 Jun 1999 10:32:19 -0600 |
| Reply-To: | Jack Hamilton <JackHamilton@FIRSTHEALTH.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Jack Hamilton <JackHamilton@FIRSTHEALTH.COM> |
| Subject: | Re: Re[2]: missing obs data sets question |
|
| Content-Type: | text/plain; charset=US-ASCII |
You might want to check the ANOBS attribute first, to find out whether SAS knows the number of observations. If all you want to know is whether the dataset has 0 obs or non-zero obs, you could use the ANY attribute instead of NLOBS (I haven't checked to see whether deleted records show up).
Also, in version 7, the NLOBSF attribute is available; it takes OBS=, FIRSTOBS=, and WHERE= into account when counting observations.
--
JackHamilton@FirstHealth.com
Development Manager, METRICS
First Health, West Sacramento, California USA
>>> GORRELP1 <GORRELP1@WESTAT.COM> 03Jun1999 5:37 AM >>>
David,
An efficient way to get the number of obs in a SAS dataset is as follows:
%let id_num = %sysfunc(open(SOME_DSN));
%let numobs = %sysfunc(attrn(&id_num,nlobs));
%let clz_dsn = %sysfunc(close(&id_num));
Now you have a macrovariable NUMOBS you can reference in conditionals or
whereever you need. Also, NLOBS contrasts with NOBS in referring only to
observations not marked for deletion. See the Online Help for ATTRN.
Paul Gorrell
gorrelp1@westat.com
____________________Reply Separator____________________
Subject: Re: missing obs data sets question
Author: David Johnson <dkvjcns@IBM.NET>
Date: 06/03/1999 12:22 AM
Jacks caution is quite timely. We have had similar difficulties recently
when reading the dictionary.
I also discovered that reading the TABLES dictionary was taking some 15
seconds in our application, which was an unconscionable delay in an
interactive user session. Here is a comparison I ran off site:
230 Proc SQL STimer;
NOTE: The SQL Statement used 0.0 seconds.
231 Create Table TEMPCONT as
232 Select LIBNAME, MEMNAME, NOBS from
233 DICTIONARY.TABLES
234 Where Substr( MEMNAME,1,4) Eq 'LINE';
ERROR: Libname USAGE is not assigned.
NOTE: Table WORK.TEMPCONT created, with 25 rows and 3 columns.
NOTE: The SQL Statement used 3.41 seconds.
235 Quit;
NOTE: The PROCEDURE SQL used 0.05 seconds.
Granted, the lack of the USAGE library may affect the outcome, but nowhere
near as much as 24 librefs for the application and most of these assigned on
a LAN through UNCs. As if this wasn't slow enough, it is even slower on NT
than on Windows 95.
The following is my preferred method, longer hand, easier for newer
programmers less experienced in SQL to understand and considerably faster.
236
237 Proc Datasets Lib = WORK NoList;
238 Contents Data = _ALL_ NoPrint Out=WORK.TEMPCONT;
239 Quit;
NOTE: The data set WORK.TEMPCONT has 53 observations and 35 variables.
NOTE: The PROCEDURE DATASETS used 0.38 seconds.
240
241 Data TEMPCONT;
242 Set TEMPCONT(Keep = LIBNAME MEMNAME NOBS
243 Where = ( MEMNAME Eq: 'LINE') );
244 By LIBNAME MEMNAME;
245 If First.MEMNAME;
246 Run;
NOTE: The data set WORK.TEMPCONT has 25 observations and 3 variables.
NOTE: The DATA statement used 0.11 seconds.
Now you have a dataset containing one entry per member with its count. One
caution, the use of 'OUT=WORK.TEMPCONT' as a fully specified destination is
deliberate. Using a single level name does not necessarily write
WORK.TEMPCONT, but in fact writes TEMPCONT into the library specified on the
Datasets LIB= parameter. A small trap there, especially if you are reading
a protected drive.
regards
David
----- Original Message -----
From: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
To: <SAS-L@AKH-WIEN.AC.AT>
Sent: 02 June 1999 20:59
Subject: Re: missing obs data sets question
> Yes, but keep in mind that there are circumstances under which NOBS will
not return the actual number of observations in a dataset. It doesn't
happen often, but it does happen. The main things to watch out for are
views and datasets with deleted observations.
>
>
>
> --
> JackHamilton@FirstHealth.com
> Development Manager, METRICS
> First Health, West Sacramento, California USA
>
>
> >>> "Newhouse, Russell" <Russell.Newhouse@WL.COM> 02Jun1999 12:42 PM >>>
> One possible method could be to look at the DICTIONARY.TABLES table that
SAS
> creates. You can use a SQL query to look at the value of NOBS (number of
> observations) for the appropriate MEMNAME (data set name).
>
> Russell Newhouse
> Parke-Davis Pharmaceutical Research
> 2800 Plymouth Road
> Ann Arbor, MI 48188
> (734) 622-5006
> Russell.Newhouse@wl.com
>
> -----Original Message-----
> From: Doug Conrad [mailto:DConrad@HER-CHER.ORG]
> Sent: Wednesday, June 02, 1999 3:53 PM
> To: SAS-L@UGA.CC.UGA.EDU
> Subject: missing obs data sets question
>
>
> I have a range of small data sets sequentially named line1--line25.
> These are generally 1 line datasets that go into a proc report.
> My problem: sometime zero obs will be returned in the datasets
> thereby dropping them as a line item in the proc report. I want all lines
> that have zero/missing to just produce a "0.00".
> What I would like to do is go through a macro loop and check if each
> dataset is empty, and if it is, then give it one observation that will
> then produce a corresponding line in proc report.
>
> %syserror doesn't look right. I've set the program up so that the files
> 'exist' but am not quite sure how to macro code this.
>
> Any ideas?
> Thanks
> doug conrad
> dconrad@her-cher.org
>
|