Process Metadata: Direct (from Fraktal SAS Programming)
Partially, step 1 in direct approach looks quite familiar from the numbered approach except that no parameters are populated, neither a segmented list, nor a limited number of single values.
/* generate the list itself */ proc sql noprint; create table age_list as select distinct age from sashelp.class ; quit;
As indicated by the name, the direct approach leaves parameter values in the data table until needed. When necessary, the value is DIRECTLY read into a parameter and used instantly.
Determination of the number of elements remains totally unchanged.
/* obtain the number of elements */ data _null_; set age_list end = eof; if eof then do; call symput("age_grps",trim(left(put(_N_,8.)))); end; run;
As promised, the loop hosting the utilization of parameter values also populates the parameter directly from the data table.
This approach makes use of the SAS Systems capability for direct record access. Whereas default SAS data table access is performed sequentially, it is also possible to directly jump to a specific record and read until an also specified record number. When data set options FIRSTOBS and OBS are set identical, then exactly one record is directly accessed and read.
/* utilize list elements */ %DO age_indx = 1 %TO &AGE_GRPS.; data _null_; set age_list(firstobs = &AGE_INDX. obs = &AGE_INDX.); call symput("age_grp",trim(left(put(age,8.)))); run; proc print noobs data = sashelp.class ; where age = &AGE_GRP.; run; %END;
Obviously the DIRECT approach is 1st choice when the number of parameters exceeds limits imposed by LIST getting too long or oversight getting lost in the NUMBERED approach.