Tips:Execution Time Macro Variable Resolution

From sasCommunity
Jump to: navigation, search

Usually, when macro variables are resolved in a DATA step, doing so before the compilation phase does just what you want. However sometimes you can improve performance and shorten your code structures by resolving the macro variables during the execution phase.

The incoming data set has a variable CODE which takes on the values 1, 2, and 3. A weight adjustment factor has been stored in corresponding macro variables &CORR1, &CORR2, and &CORR3. In this DATA step, the macro variables are resolved before the compilation phase.

Through the use of the executable SYMGET function, we can retrieve a macro variable based on the value of a variable on the PDV. Here the variable CODE, which is on the incoming data set, is used to form the name of the macro variable to be retrieved by SYMGET.

%let corr1 = 1.1;
%let corr2 = 2.2;
%let corr3 = 3.3;
data corrwt;
   set weights;
   if code=1 then wt = wt*&corr1;
   else if code=2 then wt = wt*&corr2;
   else if code=3 then wt = wt*&corr3;
   run;
%let corr1 = 1.1;
%let corr2 = 2.2;
%let corr3 = 3.3;
data corrwt;
   set weights;
   wt = wt*symget(catt('corr',code));
   run;


Submitted By Art Carpenter (talk)