macro functioning

Reply
Contributor
Posts: 64

macro functioning

Dear Experts,

Please explain the below mentioned macros as I have got this to execute but it seems complex to me.

1. * Defines a macro variable containing a count of distinct basket

dimensions;

%let dsid=%sysfunc(open(&lib..basket_dimension,i));

        %let tot_basket_dimensions=%sysfunc(attrn(&dsid,nobs));

%let rc=%sysfunc(close(&dsid));

%put ;%put Count of distinct &basket_dimension: &tot_basket_dimensions;

%put ;

2. *Defines a macro variable containing a count of distinct analysis units;

%let dsid=%sysfunc(open(&lib..analysis_unit,i));

    %let tot_analysis_units=%sysfunc(attrn(&dsid,nobs));

%let rc=%sysfunc(close(&dsid));

%put ;%put Count of distinct &analysis_unit: &tot_analysis_units;

%put ;

Regards

Rahul

Super User
Super User
Posts: 7,720

Re: macro functioning

Not much to explain there, it is opening a SAS datafile, getting the observation number from the metadata, closing the datafile and displaying the number.  You could do the same in a datastep by:

data _null_;

     set sashelp.vtable (where=(libname="a libname" and memname="a dataset"));

     call symput('BASKET_DIMENSION',nobs);

run;

%put &BASKET_DIMENSION.;

Contributor
Posts: 64

Re: macro functioning

and what is the use of attrn function in following statement.

%let tot_basket_dimensions=%sysfunc(attrn(&dsid,nobs));

Super User
Super User
Posts: 7,720

Re: macro functioning

You can use the online help system to get help on specific functions.  Attrn means get a numeric attribute from dataset.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Respected Advisor
Posts: 4,137

Re: macro functioning

Ask a Question
Discussion stats
  • 4 replies
  • 195 views
  • 0 likes
  • 3 in conversation