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
(Added macro variable definitions)
(gardening)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<div style="float:right"><source lang="sas">
+
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>
 +
<tr>
 +
<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.
 +
</td>
 +
<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.
 +
</td>
 +
</tr>
 +
<tr>
 +
<td valign="top">
 +
<source lang="sas">
 
%let corr1 = 1.1;
 
%let corr1 = 1.1;
 
%let corr2 = 2.2;
 
%let corr2 = 2.2;
Line 9: Line 21:
 
   else if code=3 then wt = wt*&corr3;
 
   else if code=3 then wt = wt*&corr3;
 
   run;
 
   run;
</source></div>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.
+
</source></td>
 
+
<td valign="top">
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.
+
<source lang="sas">
 
+
%let corr1 = 1.1;
<div style="float:left"><source lang="sas">
+
%let corr2 = 2.2;
 +
%let corr3 = 3.3;
 
data corrwt;
 
data corrwt;
 
   set weights;
 
   set weights;
 
   wt = wt*symget(catt('corr',code));
 
   wt = wt*symget(catt('corr',code));
 
   run;
 
   run;
</source></div>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.
+
</source></td>  
 
+
</tr></table>
 
+
 
+
 
+
<!-- Insert any appropriate category tags - yu can have as many CATEGORY tag lines as you want.
+
    it is important to put the category tags inside the <noinclude></noinclude> block so the categories are only applied to the tip page.
+
-->
+
 
<noinclude>
 
<noinclude>
 
[[Category:SYMGET Function]]
 
[[Category:SYMGET Function]]
 
[[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 to be Reviewed]]
+
 
 +
<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)