5 users online | 5 Guests and 0 Registered

I know that the number of observations is stored in the metadata - how can I retrieve this without processing the dataset?


There are a number of character and numeric metadata attribute values which can be retrieved easily from the dataset's metadata without the requirement to process the data sequentially (which could be very time-consuming for large datasets).

One of the most commonly-desired values is the number of observations (in reality the number of 'logical' observations).  The process to retrieve this is to OPEN the dataset, retireve the value, then it is good practise to CLOSE the dataset.

Using macro variable declarations:

%let dsid    = %sysfunc(open(sashelp.zipcodes)) ;
%let nobs    = %sysfunc(attrn(&dsid,nlobs))     ;
%let dsclose = %sysfunc(close(&dsid))           ;

The DSID macro variable stores a numeric identifier associated with the dataset named by the OPEN function.  The ATTRN function retrieves a numeric attribute from the metadata - in this case the number of logical observations (NLOBS) and stores the returned value in the macro variable NOBS.  The DSCLOSE macro variable stores an identifier for the dataset named in the CLOSE function. 

Author:
Alan D Rudland
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags