<?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: Can I reference a non-existing macro variable without getting a warning? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553732#M154003</link>
    <description>&lt;P&gt;I don't understand what the problem is.&lt;/P&gt;
&lt;P&gt;It sounds like you want to conditionally update the value of the FOOTNOTES macro variable to contain the value of the LINE macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro report (footnotes .... );
%if %symexist(line) %then footnotes=&amp;amp;line|&amp;amp;footnotes;
....
%mend;

%report(footnotes=footnote1 | footnote2, ...).&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Apr 2019 17:36:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-04-24T17:36:39Z</dc:date>
    <item>
      <title>Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553650#M153971</link>
      <description>&lt;P&gt;Is there a way to reference a non-existing macro variable in a parameter of a macro call without getting a warning of a non-declared macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;E.g. %report (footnotes = &amp;amp;line | footnote1 | footnote2, ...).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to use a standard macro which declares line as global and sets it according to the linesize value. I can't declare it as global before calling the macro, then it would be resolved in the call directly, and the value set in the macro is not reflected. Note that the macro works correctly, because &amp;amp;line is not resoved in the call but only later after line is defined within the macro and the parameter footnotes is used after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see 2 possible solutions to the problem:&lt;/P&gt;
&lt;P&gt;1. somehow preventing &amp;amp;line to be resolved during the call but enabling later resolution. Quoting does not help here because I can't change the macro to add an %unquote call.&lt;/P&gt;
&lt;P&gt;2. finding a macro macro option similar to the system option var_init_chk = nonote, but I didn't find something like that.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553650#M153971</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-24T14:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553653#M153972</link>
      <description>&lt;P&gt;I don't know of such an option, but ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Couldn't you just remove &amp;amp;LINE from the macro call, and change the interior logic of the macro to add it back in once the value has been set?&amp;nbsp; If you are really not allowed to fiddle with %REPORT at all, perhaps you could construct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro report2 (footnotes_without_line=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%report (footnotes=&amp;amp;footnotes_without_line)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%* Additional logic to add back in the value of &amp;amp;LINE;&lt;/P&gt;
&lt;P&gt;%mend report2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that may not help since %REPORT finishes before you get to adjust the value of &amp;amp;FOOTNOTES.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553653#M153972</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-24T14:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553654#M153973</link>
      <description>&lt;P&gt;Use a wrapper macro to detect the presence of a macro variable with %symexist:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro checkvar(varname);
%if %symexist(&amp;amp;varname) %then &amp;amp;&amp;amp;varname; %else %str( );
%mend;

title "%checkvar(xxx)";

proc print data=sashelp.class (obs=1) noobs;
run;

%let xxx=this is a test;

title "%checkvar(xxx)";

proc print data=sashelp.class (obs=1) noobs;
run;

%symdel xxx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first proc print has an empty title, no WARNINGs in the log.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553654#M153973</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-24T14:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553658#M153974</link>
      <description>Thanks for your suggestion. Indeed I have a workaround, the standard macro&lt;BR /&gt;only provides the footnote statements, and using SASHELP.VTITLE I move the&lt;BR /&gt;footnotes 1 number up after putting &amp;amp;line into footnote1 with an additional&lt;BR /&gt;macro. The output is then correctly created. My concern is to avoid both the&lt;BR /&gt;additional macro and the WARNING.&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553658#M153974</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-24T14:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553662#M153977</link>
      <description>I know that the macro variable&lt;BR /&gt;&lt;BR /&gt;1.) does not exist&lt;BR /&gt;&lt;BR /&gt;2.) is not allowed to exist before the macro call because it would possibly&lt;BR /&gt;have a wrong value to which it is resolved too early.&lt;BR /&gt;&lt;BR /&gt;3.) is created and declared as global within the macro&lt;BR /&gt;&lt;BR /&gt;4.) is correctly set in the macro and resolved afterwards correctly when&lt;BR /&gt;using the footnotes parameter&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 24 Apr 2019 14:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553662#M153977</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-24T14:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553732#M154003</link>
      <description>&lt;P&gt;I don't understand what the problem is.&lt;/P&gt;
&lt;P&gt;It sounds like you want to conditionally update the value of the FOOTNOTES macro variable to contain the value of the LINE macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro report (footnotes .... );
%if %symexist(line) %then footnotes=&amp;amp;line|&amp;amp;footnotes;
....
%mend;

%report(footnotes=footnote1 | footnote2, ...).&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 17:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553732#M154003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-24T17:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553734#M154005</link>
      <description>&lt;P&gt;If you really really need to stick &amp;amp;LINE into your call then here is a trick that does it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;%upcase(line)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(x);
%let line=Set later;
%put ACTUAL X=%superq(x);
%put EFFECTIVE &amp;amp;=x;
%mend test;
%let line=Set earlier;
%test(x=&amp;amp;line);
%test(x=&amp;amp;&amp;amp;%upcase(line));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 17:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553734#M154005</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-24T17:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553877#M154059</link>
      <description>Thanks for your reply. I'm not quite sure if I understand you correctly. I&lt;BR /&gt;think your macro test stands for my macro report. But I can't change this&lt;BR /&gt;standard macro of my client. To achieve your result, I understand that I&lt;BR /&gt;would have to introduce the %superq function in the macro which I can't do.&lt;BR /&gt;But your values "SET EARLIER" and "SET LATER" bring me to another idea: I&lt;BR /&gt;can omit &amp;amp;line from the footnotes parameter in a first call of my macro,&lt;BR /&gt;coming out of the macro, line is correctly globally defined and I call the&lt;BR /&gt;macro a 2nd time with &amp;amp;line in the call. Fortunately the macro does not&lt;BR /&gt;produce any external output, and it's no harm to run it twice.&lt;BR /&gt;&lt;BR /&gt;So thanks again&lt;BR /&gt;&lt;BR /&gt;Hans&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Apr 2019 07:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/553877#M154059</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-25T07:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554203#M154168</link>
      <description>&lt;P&gt;OK I now see &amp;amp;&amp;amp;%upcase(line) is the trick to hide line as a macro variable and, after resolving &amp;amp;&amp;amp; to &amp;amp; in the call of macro test, within the macro x=&amp;amp;LINE is available where &amp;amp;LINE is not yet resolved. &amp;amp;&amp;amp;%substr(line,1) has the same effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Great!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2019 09:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554203#M154168</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-26T09:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554469#M154246</link>
      <description>&lt;P&gt;Me again: the program works fine, but why? Is there a restriction when resolving parameters in a macro call, that a value is passed only once? In open code, &amp;amp;&amp;amp;%upcase(line) is resolved in a first pass to &amp;amp;LINE, in a second pass then to the value of the macro variable line. Is this second pass omitted when &amp;amp;&amp;amp;%upcase(line) is the value of a parameter in a macro call? I don't find any documentation on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd question: why results&lt;/P&gt;
&lt;P&gt;%test(x=&amp;amp;%upcase(line));&lt;/P&gt;
&lt;P&gt;in:&lt;/P&gt;
&lt;P&gt;ACTUAL X=&amp;amp;%upcase(line)&lt;BR /&gt;EFFECTIVE X=&amp;amp;%upcase(line)&lt;/P&gt;
&lt;P&gt;I'd think in the first pass &amp;amp; is kept, %upcase(line) is evaluated to LINE, together &amp;amp;LINE, and without 2nd pass giving the same as with 2 ampersands where in the 1st pass &amp;amp;&amp;amp; is resolved to &amp;amp; and %upcase(line) to LINE:&lt;/P&gt;
&lt;P&gt;ACTUAL X=&amp;amp;LINE&lt;BR /&gt;EFFECTIVE X=Set later&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2019 12:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554469#M154246</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-04-27T12:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554478#M154248</link>
      <description>&lt;P&gt;It is not the macro that is the issue really.&amp;nbsp; The issue is that you need to get the &amp;amp; into the value of the macro variable (every macro parameter is a local macro variable in the macro's symbol space) without it being macro quoted so that later when the macro processor resolves the value the &amp;amp; will trigger the macro processor to resolve the reference. You will have similar issues trying to force an &amp;amp; into the value of macro variable when using the %LET statement also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to get un protected &amp;amp; and % into macro variables is to use SAS code (instead of macro code) to set the macro variable value.&amp;nbsp; For example you can use CALL SYMPUTX() function in a data step or the INTO keyword in PROC SQL code.&amp;nbsp; There you can use single quotes around the string to prevent the macro processor from evaluating the &amp;amp; reference too soon.&amp;nbsp; But the single quotes are not actually part of the value like they would be in macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('mymvar','This will resolve reference to LINE later. LINE=&amp;amp;line.');
run;
proc sql noprint;
  select 'This will resolve reference to LINE later. LINE=&amp;amp;line.'
    into :mymvar
    from sashelp.class(obs=1)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Apr 2019 15:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/554478#M154248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-27T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/562289#M157503</link>
      <description>&lt;P&gt;All now works fine, my program does what I want it to do. But I'm still wondering why &amp;amp;%upcase(line) does not work but &amp;amp;&amp;amp;%upcase(line) works as posted on &lt;SPAN class="DateTime lia-message-posted-on lia-component-common-widget-date"&gt;&lt;SPAN class="local-date"&gt;04-27-2019&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;08:18 AM&lt;/SPAN&gt;&lt;/SPAN&gt;, just for my understanding.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/562289#M157503</guid>
      <dc:creator>HWSteinberg</dc:creator>
      <dc:date>2019-05-29T14:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can I reference a non-existing macro variable without getting a warning?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/562293#M157504</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37523"&gt;@HWSteinberg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;All now works fine, my program does what I want it to do. But I'm still wondering why &amp;amp;%upcase(line) does not work but &amp;amp;&amp;amp;%upcase(line) works as posted on &lt;SPAN class="DateTime lia-message-posted-on lia-component-common-widget-date"&gt;&lt;SPAN class="local-date"&gt;04-27-2019&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;08:18 AM&lt;/SPAN&gt;&lt;/SPAN&gt;, just for my understanding.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure WHY it doesn't work. But HOW it doesn't work is that the value &amp;amp;LINE is not put into the macro variable.&amp;nbsp; Instead the value &amp;amp;%upcase(line) is put into the macro variable.&lt;/P&gt;
&lt;PRE&gt;1719  %let one=&amp;amp;%upcase(line);
1720  %let two=&amp;amp;&amp;amp;%upcase(line);
1721  %put one=%superq(one);
one=&amp;amp;%upcase(line)
1722  %put two=%superq(two);
two=&amp;amp;LINE
&lt;/PRE&gt;
&lt;P&gt;I suspect something about how it is breaking the string into tokens.&amp;nbsp; So with one &amp;amp; it treats it as one token without any macro code to resolve. With two &amp;amp; it sees it as two tokens. The first converts to &amp;amp; and the stops and the second converts to LINE.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 14:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-reference-a-non-existing-macro-variable-without-getting-a/m-p/562293#M157504</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-29T14:33:19Z</dc:date>
    </item>
  </channel>
</rss>

