<?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: Checking for unresolved macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622309#M183050</link>
    <description>&lt;P&gt;The CALL SYMPUT routine can only be used in a DATA step. You are trying to use it in open code. Also you can't check to see if a macro variable contains a blank value if it isn't yet defined. Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runStuff;
%let test = ;
%if %isblank(&amp;amp;test.) = 1 %then %do;
%put blank;
%let test = 'cycle = 0';
%end;
%else %do;
%put notblank;
%end;

%mend runStuff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 22:06:37 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2020-02-04T22:06:37Z</dc:date>
    <item>
      <title>Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622305#M183047</link>
      <description>&lt;P&gt;Hello mentors,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro variable 'test' such that when I check its value, it says unresolved macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=test ;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference TEST not resolved.&lt;/P&gt;&lt;P&gt;test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then have a code to check if the macro variable is empty or not, if empty I need to give it a default value (with the quotes) ‘cycle=0’, and I've seen snippets of this code a couple of times in these forums&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro isBlank(param);
%sysevalf(%superq(param)=,boolean)
%mend isBlank;

%macro runStuff;
%if %isblank(&amp;amp;test.) = 1 %then %do;
%put blank;
call symput('test',"'cycle = 0'");
%end;
%else %do;
%put notblank;
%end;

%mend runStuff;
%runStuff;

%put &amp;amp;=test ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But for some reason, the output value from the boolean expression is '0' instead of the expected '1'. Why would that happen when the macro is unresolved?&lt;/P&gt;&lt;P&gt;Log below for reference, appreciate the help in helping me understand this concept.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;P&gt;25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GOPTIONS ACCESSIBLE;&lt;/P&gt;&lt;P&gt;26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %macro isBlank(param);&lt;/P&gt;&lt;P&gt;27&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %sysevalf(%superq(param)=,boolean)&lt;/P&gt;&lt;P&gt;28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend isBlank;&lt;/P&gt;&lt;P&gt;29&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %macro runStuff;&lt;/P&gt;&lt;P&gt;31&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %isblank(&amp;amp;test.) = 1 %then %do;&lt;/P&gt;&lt;P&gt;32&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put blank;&lt;/P&gt;&lt;P&gt;33&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;call symput('test',"'cycle = 0'");&lt;/P&gt;&lt;P&gt;34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;36&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put notblank;&lt;/P&gt;&lt;P&gt;37&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;38&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;39&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mend runStuff;&lt;/P&gt;&lt;P&gt;40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %runStuff;&lt;/P&gt;&lt;P&gt;MLOGIC(RUNSTUFF):&amp;nbsp; Beginning execution.&lt;/P&gt;&lt;P&gt;MLOGIC(ISBLANK):&amp;nbsp; Beginning execution.&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference TEST not resolved.&lt;/P&gt;&lt;P&gt;MLOGIC(ISBLANK):&amp;nbsp; Parameter PARAM has value &amp;amp;test.&lt;/P&gt;&lt;P&gt;MLOGIC(ISBLANK):&amp;nbsp; Ending execution.&lt;/P&gt;&lt;P&gt;MLOGIC(RUNSTUFF):&amp;nbsp; %IF condition %isblank(&amp;amp;test.) = 1 is FALSE&lt;/P&gt;&lt;P&gt;MLOGIC(RUNSTUFF):&amp;nbsp; %PUT notblank&lt;/P&gt;&lt;P&gt;notblank&lt;/P&gt;&lt;P&gt;MLOGIC(RUNSTUFF):&amp;nbsp; Ending execution.&lt;/P&gt;&lt;P&gt;41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;=test ;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference TEST not resolved.&lt;/P&gt;&lt;P&gt;test&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 21:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622305#M183047</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-02-04T21:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622309#M183050</link>
      <description>&lt;P&gt;The CALL SYMPUT routine can only be used in a DATA step. You are trying to use it in open code. Also you can't check to see if a macro variable contains a blank value if it isn't yet defined. Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runStuff;
%let test = ;
%if %isblank(&amp;amp;test.) = 1 %then %do;
%put blank;
%let test = 'cycle = 0';
%end;
%else %do;
%put notblank;
%end;

%mend runStuff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 22:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622309#M183050</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-02-04T22:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622310#M183051</link>
      <description>Thank you for your response.&lt;BR /&gt;&lt;BR /&gt;The macro variable test gets created and assigned a value in a seperate unrelated query. However, in some scenarios, it does get created but there is no value assigned to it. Therefore, I used %put &amp;amp;=test ; statement before running the above code and got the following warning&lt;BR /&gt;&lt;BR /&gt;WARNING: Apparent symbolic reference TEST not resolved.&lt;BR /&gt;test&lt;BR /&gt;&lt;BR /&gt;The issue for me is that even though 'test' does not have a value assigned, when I run the above code, the boolean output is 0 instead of the expected value of 1.</description>
      <pubDate>Tue, 04 Feb 2020 22:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622310#M183051</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-02-04T22:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622313#M183053</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your response.&lt;BR /&gt;&lt;BR /&gt;The macro variable test gets created and assigned a value in a seperate unrelated query. However, in some scenarios, it does get created but there is no value assigned to it. Therefore, I used %put &amp;amp;=test ; statement before running the above code and got the following warning&lt;BR /&gt;&lt;BR /&gt;WARNING: Apparent symbolic reference TEST not resolved.&lt;BR /&gt;test&lt;BR /&gt;&lt;BR /&gt;The issue for me is that even though 'test' does not have a value assigned, when I run the above code, the boolean output is 0 instead of the expected value of 1.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is a function to check if a macro variable exists.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %symexist(TEST);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the underlying problem is caused by using the INTO clause of PROC SQL to populate the macro variable then set the default value before the query that you are using to set it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let test=0;
select count(*) format=32. into :test trimmed 
from sashelp.class where sex='UNKNOWN'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your later steps can be assured the macro variable will have a value &lt;STRONG&gt;whether or not any observations are found by the query.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 22:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622313#M183053</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T22:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622314#M183054</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp; - In that case you haven't posted the whole problem. Where do you define TEST - if it is inside another macro for example then it will only resolve in that macro and not outside it hence your warning message. If you want TEST to resolve everywhere then define it in a %GLOBAL statement - %global test; - at the start of your program.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 22:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622314#M183054</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-02-04T22:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622316#M183055</link>
      <description>I tried the symexist too, it resolves to 1.&lt;BR /&gt;&lt;BR /&gt;25 GOPTIONS ACCESSIBLE;&lt;BR /&gt;26 %global test;&lt;BR /&gt;27&lt;BR /&gt;28 %put &amp;amp;=test ;&lt;BR /&gt;SYMBOLGEN: Macro variable TEST resolves to&lt;BR /&gt;TEST=&lt;BR /&gt;29&lt;BR /&gt;30&lt;BR /&gt;31 %macro check;&lt;BR /&gt;32 %if %symexist(TEST)=0 %then %do;&lt;BR /&gt;33 %let test = 'cycle = 0';&lt;BR /&gt;34 %end;&lt;BR /&gt;35 %mend;&lt;BR /&gt;36 %check;&lt;BR /&gt;MLOGIC(CHECK): Beginning execution.&lt;BR /&gt;MLOGIC(CHECK): %IF condition %symexist(TEST)=0 is FALSE&lt;BR /&gt;MLOGIC(CHECK): Ending execution.&lt;BR /&gt;37</description>
      <pubDate>Tue, 04 Feb 2020 22:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622316#M183055</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-02-04T22:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622318#M183057</link>
      <description>I tried this too:&lt;BR /&gt;&lt;BR /&gt;%macro check;&lt;BR /&gt;%if "&amp;amp;test." = ' ' %then %do;&lt;BR /&gt;%let test = 'cycle = 0';&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%check;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;=test ;&lt;BR /&gt;&lt;BR /&gt;Log:&lt;BR /&gt;26 %macro check;&lt;BR /&gt;27 %if "&amp;amp;test." = ' ' %then %do;&lt;BR /&gt;28 %let test = 'cycle = 0';&lt;BR /&gt;29 %end;&lt;BR /&gt;30 %mend;&lt;BR /&gt;31 %check;&lt;BR /&gt;MLOGIC(CHECK): Beginning execution.&lt;BR /&gt;SYMBOLGEN: Macro variable TEST resolves to&lt;BR /&gt;MLOGIC(CHECK): %IF condition "&amp;amp;test." = ' ' is FALSE&lt;BR /&gt;MLOGIC(CHECK): Ending execution.&lt;BR /&gt;32&lt;BR /&gt;33 %put &amp;amp;=test ;&lt;BR /&gt;SYMBOLGEN: Macro variable TEST resolves to&lt;BR /&gt;TEST=</description>
      <pubDate>Tue, 04 Feb 2020 22:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622318#M183057</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2020-02-04T22:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Checking for unresolved macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622320#M183058</link>
      <description>&lt;P&gt;That doesn't make any sense as a way to check the value of a macro variable.&amp;nbsp; Your condition is not going to be changed by the value of the macro variable TEST.&amp;nbsp; A single quote character is never going to be the same as a double quote character so it is always going to be false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please clarify what you are actually trying to test.&lt;/P&gt;
&lt;P&gt;Do you want to check if the macro variable exists?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%symexist(TEST)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want to check if it has any value?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%length(%superq(test))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want to check if it has a value that is not just spaces?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysevalf(%superq(test)=,boolean)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings09/022-2009.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings09/022-2009.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 22:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Checking-for-unresolved-macro-variables/m-p/622320#M183058</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T22:45:41Z</dc:date>
    </item>
  </channel>
</rss>

