As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "Tips:Execution Time Macro Variable Resolution"

From sasCommunity
Jump to: navigation, search
(Scheduled December 29, 2014)
(updated submitted by)
Line 44: Line 44:
 
-->
 
-->
  
<!-- Please do not edit below this line, EXCEPT when promoting a tip -->
+
<!-- Please do not edit below this line, EXCEPT when promoting a tip  
 +
<div style="float:right">Submitted By [[User:ArtCarpenter|Art Carpenter]] ([[User talk:ArtCarpenter|talk]])</div>-->
 
<div style="float:right">Submitted By [[User:ArtCarpenter|Art Carpenter]] ([[User talk:ArtCarpenter|talk]])</div>
 
<div style="float:right">Submitted By [[User:ArtCarpenter|Art Carpenter]] ([[User talk:ArtCarpenter|talk]])</div>
 
<noinclude>
 
<noinclude>
 
[[Category:Tip in Use]]
 
[[Category:Tip in Use]]
 
</noinclude>
 
</noinclude>

Revision as of 03:09, 18 November 2015

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)