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
(Tip Promoted)
(gardening)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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.
+
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.
 
<table>
 
<table>
 
<tr>
 
<tr>
 
<td valign="bottom">
 
<td valign="bottom">
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.
+
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.
 
</td>
 
</td>
 
<td valign="bottom">
 
<td valign="bottom">
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.
+
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.
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 37: Line 37:
 
[[Category:Macro Language]]
 
[[Category:Macro Language]]
 
</noinclude>
 
</noinclude>
<!-- Provide links to other resources:
 
- If the links are pages on sasCommunity update the "WikiReadMore" line and replace "PAGENAME" with the name of the sasCommunity.org page.
 
- If the links are external (e.g., the sas support site, other external links, and so on, updated the "External ReadMore" line and replace "URL" with the full url including the http:
 
- You can include as many of these lines as you want
 
- if you don't have such links, just delete the line(s)
 
-->
 
  
<!-- 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>
[[Category:Tip Promoted]]
+
 
 +
<noinclude>
 +
[[Category:Tip in Use]]
 +
</noinclude>

Latest revision as of 08:08, 29 December 2016

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)