<?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: how do i resolve a Macro variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813329#M320975</link>
    <description>&lt;P&gt;I cannot help without a replicable example. Here I'm assuming that you call the macro in a loop.&lt;/P&gt;
&lt;P&gt;For such circumstances I prefer to use call execute after creating a REF dataset containing all the possible values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro printds(ds=);
proc print data=&amp;amp;ds.;
run;
%mend printds;
%*printds(ds=sashelp.class);

data ref;
   set sashelp.vtable (where=(upcase(libname)='SASHELP' and 
                              upcase(memname) like 'C%'));
run;

data _null_;
    set ref;
    call execute('%printds(ds=sashelp.' || memname || ');');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 May 2022 06:35:31 GMT</pubDate>
    <dc:creator>xxformat_com</dc:creator>
    <dc:date>2022-05-14T06:35:31Z</dc:date>
    <item>
      <title>how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813307#M320959</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This might look silly, but i am not able to resolve a Macro variable.&lt;/P&gt;&lt;P&gt;I am trying to create log files for a program and running it in loop for multiple dates for a single .sas program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest me on this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let tst = t1; /*for testing purpose*/
/*StrLog Macro creates the log file at the give location in the macro var dirname*/

%StrLog(PName=%str(&amp;amp;PName ),PrinttoName = %str(&amp;amp;DirNme.\LOGS\&amp;amp;PName .&amp;amp;&amp;amp;Pg1YYMM&amp;amp;i.&amp;amp;tst..log) , ClearLog=N);&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;LOG :&lt;BR /&gt;&lt;BR /&gt;WARNING: Apparent symbolic reference P1YYMM1_T1 not resolved.&lt;BR /&gt;&amp;amp;P1YYMM1_t1..log&lt;BR /&gt;&lt;BR /&gt;If i assign anything to the Macro tst, its not resolving pls check the below.&lt;BR /&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable MNTH1 resolves to 202103&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103&lt;BR /&gt;SYMBOLGEN: Macro variable PNME resolves to SALES&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable TST resolves to t&lt;BR /&gt;WARNING: Apparent symbolic reference P1YYMM1T not resolved.&lt;BR /&gt;i==&amp;gt;&amp;gt; 1 202103 12103 SALES&amp;amp;P1YYMM1t..log&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;and if I don't assign anything to the macro variable &lt;CODE class=""&gt;tst it&amp;nbsp;works&amp;nbsp;fine.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable MNTH1 resolves to 202103&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103&lt;BR /&gt;SYMBOLGEN: Macro variable PNME resolves to SALES&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable TST resolves to&lt;BR /&gt;SYMBOLGEN: Macro variable P1YYMM1 resolves to 12103&lt;BR /&gt;i==&amp;gt;&amp;gt; 1 202103 12103 SALES12103.log&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to make sure it works in both the scenarios.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 00:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813307#M320959</guid>
      <dc:creator>Santt0sh</dc:creator>
      <dc:date>2022-05-14T00:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813309#M320961</link>
      <description>&lt;P&gt;To debug macros, first turn on the debugging options by running this command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then run the macro again and show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for the macro. Please copy the log as text and then paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. DO NOT SKIP THIS STEP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66123iA4EF494F9CA0F6EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also show us the code for macro %StrLog&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 22:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813309#M320961</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-13T22:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813329#M320975</link>
      <description>&lt;P&gt;I cannot help without a replicable example. Here I'm assuming that you call the macro in a loop.&lt;/P&gt;
&lt;P&gt;For such circumstances I prefer to use call execute after creating a REF dataset containing all the possible values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro printds(ds=);
proc print data=&amp;amp;ds.;
run;
%mend printds;
%*printds(ds=sashelp.class);

data ref;
   set sashelp.vtable (where=(upcase(libname)='SASHELP' and 
                              upcase(memname) like 'C%'));
run;

data _null_;
    set ref;
    call execute('%printds(ds=sashelp.' || memname || ');');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2022 06:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813329#M320975</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2022-05-14T06:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813333#M320979</link>
      <description>&lt;P&gt;I tried to recreate some of the macro resolution in your program:&lt;/P&gt;
&lt;PRE&gt; 69         %let Pg1YYMM1=12103;
 70         %let I=1;
 71         %let tst=_t1;
 72         %put &amp;amp;&amp;amp;Pg1YYMM&amp;amp;i.&amp;amp;tst..log;
 WARNING: Apparent symbolic reference PG1YYMM1_T1 not resolved.
 &amp;amp;Pg1YYMM1_t1.log&lt;/PRE&gt;
&lt;P&gt;What seems to happen is that the TST variable becomes part of the macro variable name that is resolved in the second parse through the compiler (everything from "&amp;amp;&amp;amp;" up to the double period before "log").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you double the period before "&amp;amp;tst" as well, it may work:&lt;/P&gt;
&lt;PRE&gt; 69         %let Pg1YYMM1=12103;
 70         %let I=1;
 71         %let tst=_t1;
 72         %put &amp;amp;&amp;amp;Pg1YYMM&amp;amp;i..&amp;amp;tst..log;
 12103_t1.log&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2022 09:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813333#M320979</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-05-14T09:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813335#M320981</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183704"&gt;@Santt0sh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I specifically asked to see the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log, as well as the macro code. You have not provided either.&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 10:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813335#M320981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-14T10:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813341#M320987</link>
      <description>&lt;P&gt;tst itself is a macro variable. Try adding one more ampersand before it as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%StrLog(PName=%str(&amp;amp;PName ),PrinttoName = %str(&amp;amp;DirNme.\LOGS\&amp;amp;PName .&amp;amp;&amp;amp;Pg1YYMM&amp;amp;i.&amp;amp;&amp;amp;tst..log) , ClearLog=N);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2022 12:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813341#M320987</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-05-14T12:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813347#M320991</link>
      <description>&lt;P&gt;You probably have over complicated things.&lt;/P&gt;
&lt;P&gt;Please explain WHY you are calling the macro in this strange way.&amp;nbsp; Especially the first two parameter values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%StrLog
(PName=%str(&amp;amp;PName )
,PrinttoName = %str(&amp;amp;DirNme.\LOGS\&amp;amp;PName .&amp;amp;&amp;amp;Pg1YYMM&amp;amp;i.&amp;amp;tst..log)
,ClearLog=N
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;For the first parameter:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Do you really want to pass in a space after the value of the external macro PNAME when passing the value into the macro as the parameter PNAME?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;For the second parameter:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Why are you adding macro quoting around the value?&amp;nbsp; Do your directories include commas? Unbalanced parentheses?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the macro variable I really have the value 1_?&amp;nbsp; That seems really strange.&amp;nbsp; If not then were did the underscore in your error message come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really want a period after the space when using PNAME to construct PRINTTONAME?&amp;nbsp; Note there is not need to use %STR() for that space as it is followed by a non space character so will not "disappear".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want the value of TST to become part of the macro name you are generating by appending the value of I to the string PG1YYMM then add another period after &amp;amp;I.&amp;nbsp; The first will mark the end of I and the second the end of PG1YYMM1_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a macro variable named PG1YYMM1_ ?&amp;nbsp; If not then why have the &amp;amp;&amp;amp; before PG1YYMM?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;DirNme.\LOGS\&amp;amp;PName .&amp;amp;&amp;amp;Pg1YYMM&amp;amp;i..&amp;amp;tst..log&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 15:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813347#M320991</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-14T15:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: how do i resolve a Macro variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813361#M321001</link>
      <description>&lt;P&gt;It's too difficult to believe everything you have posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say you have a macro variable named PNAME.&amp;nbsp; But SAS doesn't find that.&amp;nbsp; It only finds PNME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your %LET statement says you assign a value of t1 to the macro variable TST.&amp;nbsp; But SAS finds that it resolves to t, not t1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say you have problems with a macro variable named P1YYMM1_T1.&amp;nbsp; But the original string doesn't contain an underscore, nor any code that would add an underscore to the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have to ignore your details as being of questionable accuracy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there is one piece that seems interesting.&amp;nbsp; You say the code (whatever it actually is) runs the first time but not the second time.&amp;nbsp; For that, I would take a wild guess at the problem lying with nesting the repeated %STR function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PName=%str(&amp;amp;PName ),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try it this way instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PName=%str(%unquote(&amp;amp;PName) ),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's a long-shot guess, but can't hurt and might help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 May 2022 00:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-i-resolve-a-Macro-variable/m-p/813361#M321001</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-05-15T00:21:55Z</dc:date>
    </item>
  </channel>
</rss>

