<?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 how to check if a macro variable exists.... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206121#M38311</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I have a few macro variables like this:&lt;/P&gt;&lt;P&gt;cat1s1, cat1s2, cat1s3, cat2s1, cat2s2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i need a loop in&amp;nbsp; my code:&lt;/P&gt;&lt;P&gt;%do i=1 %to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do j=1 %to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***&lt;SPAN style="color: #0000ff;"&gt;if macro variable &amp;amp;&amp;amp;cat&amp;amp;i.s&amp;amp;j exist&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do i put the blue color sentence into code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Mar 2015 19:12:55 GMT</pubDate>
    <dc:creator>sandyming</dc:creator>
    <dc:date>2015-03-19T19:12:55Z</dc:date>
    <item>
      <title>how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206121#M38311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I have a few macro variables like this:&lt;/P&gt;&lt;P&gt;cat1s1, cat1s2, cat1s3, cat2s1, cat2s2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i need a loop in&amp;nbsp; my code:&lt;/P&gt;&lt;P&gt;%do i=1 %to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do j=1 %to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***&lt;SPAN style="color: #0000ff;"&gt;if macro variable &amp;amp;&amp;amp;cat&amp;amp;i.s&amp;amp;j exist&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do i put the blue color sentence into code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 19:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206121#M38311</guid>
      <dc:creator>sandyming</dc:creator>
      <dc:date>2015-03-19T19:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206122#M38312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The function %Symexist&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Mar 2015 19:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206122#M38312</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-03-19T19:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206123#M38313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i know the function, but I can not use it as %symexist(&amp;amp;&amp;amp;cat&amp;amp;i.s&amp;amp;j), can I?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 16:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206123#M38313</guid>
      <dc:creator>sandyming</dc:creator>
      <dc:date>2015-03-20T16:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206124#M38314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%symexist(cat&amp;amp;i.s&amp;amp;j.) is what you want to be checking if the macro variable is like cat1s1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 16:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206124#M38314</guid>
      <dc:creator>AYBiBTU</dc:creator>
      <dc:date>2015-03-20T16:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206125#M38315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An alternate method is to put the macro variable names in a %GLOBAL statement. Then you can simply test with %IF or %LENGTH statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Mar 2015 03:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206125#M38315</guid>
      <dc:creator>JayCorbett</dc:creator>
      <dc:date>2015-03-22T03:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206126#M38316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;JayCorbett wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;An alternate method is to put the macro variable names in a %GLOBAL statement. Then you can simply test with %IF or %LENGTH statements.&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;That way you create a global macro variable and symexist will always return true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro %symexist is available as normal sas function. See &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002636452.htm" title="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a002636452.htm"&gt;SAS(R) 9.2 Macro Language: Reference&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 11:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206126#M38316</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2015-03-23T11:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206127#M38317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should have been more complete with my answer. if cat1s1, cat1s2, cat1s3, cat2s1, cat2s2 were declared in a %GLOBAL statement. Then to test for existence you could use&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%If &amp;amp;&amp;amp;CAT1S&amp;amp;i^=%str()&lt;/STRONG&gt; OR&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%If %Length(&amp;amp;&amp;amp;CAT1S&amp;amp;i)&amp;gt;0&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you'll be happier if you&lt;/P&gt;&lt;P&gt;%LET &amp;amp;CAT1=&amp;amp;&amp;amp;CAT1S&amp;amp;i;&lt;/P&gt;&lt;P&gt;Then referencing it is not so tedious....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 14:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206127#M38317</guid>
      <dc:creator>JayCorbett</dc:creator>
      <dc:date>2015-03-24T14:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206128#M38318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could I ask why your doing this?&amp;nbsp; The syntax you use CATxSx seems to my mind, to be more closely associated with an array.&amp;nbsp; Why do you need to use macro language to do this, just use a basic datastep with and array and loop over it.&amp;nbsp; If you can provide and example of what you want...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 15:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206128#M38318</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-03-24T15:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if a macro variable exists....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206129#M38319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is not a test for existence.&amp;nbsp; That is a test for whether it is empty.&lt;/P&gt;&lt;P&gt;They are two different things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example if I want to write a macro than can optionally update the macro variable RETURN I could add this line of code to the top of the macro to check if the macro variable exists and if it doesn't make a local version so that the value is not returned.&amp;nbsp; &lt;/P&gt;&lt;P&gt;%if not %symexist(RETURN) %then %local return ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice that this will work better than adding a %GLOBAL statement since it will allow for the existence of the macro variable in the local scope of a calling macro environment.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 17:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-a-macro-variable-exists/m-p/206129#M38319</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-24T17:00:59Z</dc:date>
    </item>
  </channel>
</rss>

