<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: delayed resolution in sas macro vars in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236655#M43367</link>
    <description>&lt;P&gt;I believe this magic is not possible as a function style macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When passing a value to a macro variable which contains an ampersand you must quote the value however you code it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could of course wrap your data step into a ma&lt;SPAN&gt;cro and then call this macro with two parameters.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro not_so_magic(l,r);
  %global &amp;amp;l;
  data _null_; 
    call symput("&amp;amp;l",'&amp;amp;'||"&amp;amp;r"); 
  run;
%mend;

%not_so_magic(b,a)
%let a=33; 
%put &amp;amp;=b;
%let a=44; 
%put &amp;amp;=b;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Nov 2015 19:24:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-11-26T19:24:05Z</dc:date>
    <item>
      <title>delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236647#M43365</link>
      <description>&lt;P&gt;With a data step, I can put a macro variable inside another one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;data _null_;&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;&amp;nbsp; call symput('b','&amp;amp;a');&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;So &amp;amp;a is now inside b.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;Check:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=33; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%put &amp;amp;b;&lt;/FONT&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;==&amp;gt; 33&lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=44;&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%put &amp;amp;b;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;==&amp;gt; 44&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;How can I do the same without a datastep, with pure macro programming?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;So the code should look like:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;%let b= ???(&amp;amp;a);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=33; &lt;BR /&gt;%put &amp;amp;b; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=44;&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%put &amp;amp;b;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;Note that I want to use &amp;amp;b without unquoting. With unquoting it is easy:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" face="Courier New"&gt;&lt;FONT size="2" face="Courier New"&gt;%let b=%nrstr(&amp;amp;a); &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=33;&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%put --- %unquote(&amp;amp;b);&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%let a=44;&lt;/FONT&gt; &lt;BR /&gt;&lt;FONT size="2" face="Courier New"&gt;%put --- %unquote(&amp;amp;b);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that is not what I want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 19:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236647#M43365</guid>
      <dc:creator>JMS</dc:creator>
      <dc:date>2015-11-26T19:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236655#M43367</link>
      <description>&lt;P&gt;I believe this magic is not possible as a function style macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When passing a value to a macro variable which contains an ampersand you must quote the value however you code it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could of course wrap your data step into a ma&lt;SPAN&gt;cro and then call this macro with two parameters.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro not_so_magic(l,r);
  %global &amp;amp;l;
  data _null_; 
    call symput("&amp;amp;l",'&amp;amp;'||"&amp;amp;r"); 
  run;
%mend;

%not_so_magic(b,a)
%let a=33; 
%put &amp;amp;=b;
%let a=44; 
%put &amp;amp;=b;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 19:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236655#M43367</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-26T19:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236661#M43372</link>
      <description>&lt;P&gt;What about&amp;nbsp;this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let c=%sysfunc(dosubl(data _null_; call symput('b','&amp;amp;a'); run;));
%let a=33; 
%put &amp;amp;b;
%let a=44; 
%put &amp;amp;b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ok, it says "%let c=...", not "%let b=...", but what's in a name, after all?&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 20:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236661#M43372</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-26T20:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236664#M43374</link>
      <description>&lt;P&gt;Its not that I need the solution for any project.&lt;/P&gt;
&lt;P&gt;I just want to learn about macro and how I can put &amp;amp;a into b.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 20:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236664#M43374</guid>
      <dc:creator>JMS</dc:creator>
      <dc:date>2015-11-26T20:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236669#M43376</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Here is a data-step free solution */

%let b=&amp;amp;&amp;amp;%unquote(a);
%let a=33; 
%put &amp;amp;b;
%let a=44; 
%put &amp;amp;b;


/* If you dislike the %UNQUOTE function and know the ASCII table, try this */

%let b=&amp;amp;&amp;amp;%sysfunc(byte(97));
%let a=33; 
%put &amp;amp;b;
%let a=44; 
%put &amp;amp;b;


/* Similar, but showing the "a" in the definition of b: */

%let b=&amp;amp;&amp;amp;%sysfunc(byte(%sysfunc(rank(a))));
%let a=33; 
%put &amp;amp;b;
%let a=44; 
%put &amp;amp;b;


/* Yet another option: */

%let b=&amp;amp;&amp;amp;%sysfunc(cat(a));
%let a=33;
%put &amp;amp;b;
%let a=44;
%put &amp;amp;b;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Nov 2015 21:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236669#M43376</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-26T21:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236695#M43383</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Nice! The doubled ampersand allows you to pass in the ampersand without quoting and after that anything will do that allows to pass in the 'a' without adding a quote to the ampersand but still in a way that the tokenizer doesn't treat it as a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here another option&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let b=&amp;amp;&amp;amp;%left(a);
%let a=33; 
%put b has value: &amp;amp;b;
%let a=44; 
%put b has value: &amp;amp;b;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Nov 2015 04:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236695#M43383</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-27T04:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236719#M43386</link>
      <description>&lt;P&gt;The question I wouold ask is why? &amp;nbsp;I find that 99% of tasks can be done in Base SAS. &amp;nbsp;Macro is a utility language to help in generate repeating code and such like, its just a text generator at the end of the day. &amp;nbsp;If I come across a program which has more than one ampersand or percentage in a line, I just delete the program and start again. &amp;nbsp;Have yet to see a valid reason for resorting to macro when re-shaping of data and array/aggregates don't do the same job.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 10:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236719#M43386</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-27T10:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: delayed resolution in sas macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236762#M43392</link>
      <description>&lt;P&gt;BTW, if you want to look what is "really" in &amp;amp;b, use %superq(b)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 16:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/delayed-resolution-in-sas-macro-vars/m-p/236762#M43392</guid>
      <dc:creator>JMS</dc:creator>
      <dc:date>2015-11-27T16:58:08Z</dc:date>
    </item>
  </channel>
</rss>

