4 users online | 4 Guests and 0 Registered

Can I retrieve metadata from an empty dataset?


Whn a dataset contains values, the normal experience is that the dataset is processed sequentially, and values can, for example, can be retrieved and stored in maro variables.

Consider the code:

data class ; 
  set sashelp.class ;
run ;

data class2 ;
  set class (obs = 1) nobs = obcount ;
    call symputx('obcount',obcount) ;
    call symputx('age'    ,age)     ;
run ;

%put &=obcount 
     &=age
    ;

Which retuns vaues in the LOG for the OBCOUNT variable retrieved from metadata, and the AGE variable retrieved from data:

 NOBS=19       AGE=14

However if the code is attempted against an empty dataset:

data class ; 
  if 0 then set sashelp.class ;
stop ;
run ;

data class2 ;
  set class (obs = 1) nobs = obcount ;
    call symputx('obcount',obcount) ;
    call symputx('age'    ,age)     ;
run ;

%put &=obcount 
     &=age
    ;

the LOG contains neither vaue, despite the stored metadata value of '0' for the record count being available.

WARMING: Apparent symbolic reference OBCOUNT not resolved.
WARMING: Apparent symbolic reference AGE not resolved.

It is the placement of the CALL routine below the SET statement which is causing the issue here.  As there is no sequential processing of the dataset listed on the SET statement, the additional statements are not processed.

Because the OBS= stored value is available to the system at COMPILE time, the CALL routing retrieing the value can be placed above the SET statement, and avoid being ignored:

data class ; 
  if 0 then set sashelp.class ;
stop ;
run ;

data class2 ;
    call symputx('obcount',obcount) ;
  set class (obs = 1) nobs = obcount ;
    call symputx('age'    ,age)     ;
run ;

%put &=obcount 
     &=age
    ;

 

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

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags