<?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 Want to check if macro variable = 0 as part of %if condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148253#M29325</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%ifSample code is below. It is a simplification-- I am calling the macro CheckData as part of a bigger macro. I want to check the data set &amp;amp;gdatasrc._forecast to see if the maximum of a variable is zero-- if so, I want to avoid running a report later on in the project. I also want to be able to email myself a report that tells me what types of anomalies were encountered (The CheckDataMsg1 macro).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SQL statement works and I get the macro variable to equal to 0 but there are leading and trailing blanks. I've tried using %STR, %EVAL, and other functions with which I'm familiar (though haven't used much) to try and get SAS to evaluate that %IF as TRUE but it's always turning out false. I want to use the same if condition to control whether or not I run and distribute the reports later in the program that I referenced later so it will be a crucial component (and the reason for needing it to be in the global symbol table).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What am I doing wrong/what do I need to add to get the %if to evaluate as true? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro Bigger-Macro(gdatasrc);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;%macro CheckData;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %global &amp;amp;gdatasrc._maxeffort;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; proc sql;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select max(effort) into :&amp;amp;gdatasrc._maxeffort from &amp;amp;gdatasrc._forecast;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %if&amp;nbsp; &amp;amp;&amp;amp;gdatasrc._maxeffort = 0 %then %do;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; %global CheckDataMsg1=Most Recent Date has all zeroes for effort (&amp;amp;gdatasrc.);&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; %mend;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Mar 2014 20:39:36 GMT</pubDate>
    <dc:creator>cau83</dc:creator>
    <dc:date>2014-03-18T20:39:36Z</dc:date>
    <item>
      <title>Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148253#M29325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%ifSample code is below. It is a simplification-- I am calling the macro CheckData as part of a bigger macro. I want to check the data set &amp;amp;gdatasrc._forecast to see if the maximum of a variable is zero-- if so, I want to avoid running a report later on in the project. I also want to be able to email myself a report that tells me what types of anomalies were encountered (The CheckDataMsg1 macro).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SQL statement works and I get the macro variable to equal to 0 but there are leading and trailing blanks. I've tried using %STR, %EVAL, and other functions with which I'm familiar (though haven't used much) to try and get SAS to evaluate that %IF as TRUE but it's always turning out false. I want to use the same if condition to control whether or not I run and distribute the reports later in the program that I referenced later so it will be a crucial component (and the reason for needing it to be in the global symbol table).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What am I doing wrong/what do I need to add to get the %if to evaluate as true? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro Bigger-Macro(gdatasrc);&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;%macro CheckData;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %global &amp;amp;gdatasrc._maxeffort;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; proc sql;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select max(effort) into :&amp;amp;gdatasrc._maxeffort from &amp;amp;gdatasrc._forecast;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %if&amp;nbsp; &amp;amp;&amp;amp;gdatasrc._maxeffort = 0 %then %do;&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; %global CheckDataMsg1=Most Recent Date has all zeroes for effort (&amp;amp;gdatasrc.);&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt; %end;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt; %mend;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 20:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148253#M29325</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-03-18T20:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148254#M29326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Leading and trailing blanks won't make a difference in your comparison.&amp;nbsp; The problem is that you need another ampersand:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;&amp;amp;&amp;amp;gdatasrc._maxeffort=0 %then %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2014 21:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148254#M29326</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-03-18T21:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148255#M29327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, can I ask why that is the case? I knew (thought I knew) I needed 2 ampersands but what is the third one doing?Looking back I can see that it was not fully resolving the variable in the way I needed but I do not understand why...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 14:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148255#M29327</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-03-19T14:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148256#M29328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So say that &lt;/P&gt;&lt;P&gt;%let &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;gdatasrc = XXX ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Then when SAS evaluates &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; &amp;amp;&amp;amp;&amp;amp;gdatasrc._maxeffort it will make two passes.&amp;nbsp; After the first it will have convert the first two &amp;amp; into one and used the third to resolve &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;amp;gdatasrc. to XXX.&amp;nbsp; So for the second pass it is looking at &amp;amp;XXX_maxeffort which is the variable that you set in the SQL code.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With only two &amp;amp; the first pass just converts the two into one and you end of with the same as if you had only used one &amp;amp; to begin with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note you should probably add a %LET before the proc sql call to set the value that you want the new global macro variable to have when there are no records in the input data set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148256#M29328</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-19T15:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148257#M29329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;With only two &amp;amp; the first pass just converts the two into one and you end of with the same as if you had only used one &amp;amp; to begin with.&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Tom, it's making more sense now. But now I'm wondering when would one ever use only 2 ampersand's?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148257#M29329</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-03-19T15:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148258#M29330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use it when doing macro variable "arrays".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let name1=Fred ;&lt;/P&gt;&lt;P&gt;%let name2=Sam;&lt;/P&gt;&lt;P&gt;%let i=2;&lt;/P&gt;&lt;P&gt;%put &amp;amp;&amp;amp;name&amp;amp;i ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148258#M29330</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-19T15:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148259#M29331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two ampersands are often used when you need to delay resolution until a string on the right can resolve.&amp;nbsp; It's easier to take an example rather than figure out what that means.&amp;nbsp; Let's say you have 10 macro variables named v1 - v10 that you would like to process.&amp;nbsp; (To illustrate, all we'll do is print their values.)&amp;nbsp; You might use code like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %put &amp;amp;&amp;amp;v&amp;amp;i;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When &amp;amp;i is 1, after the first pass through this resolves into &amp;amp;v1.&amp;nbsp; After the second pass through, it resolves into the value of the macro variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148259#M29331</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-03-19T15:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148260#M29332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you had made the beginning of the macro variable name the constant instead of the ending then you could have used &amp;amp;&amp;amp; in your example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let gdatasrc=xxx ;&lt;/P&gt;&lt;P&gt;%let maxeffort_&amp;amp;gdatasrc = 101 ;&lt;/P&gt;&lt;P&gt;%put &amp;amp;&amp;amp;maxeffort_&amp;amp;gdatasrc ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148260#M29332</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-03-19T15:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Want to check if macro variable = 0 as part of %if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148261#M29333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahh this makes sense, in fact reminds me that I have done that before (which is why it nagged me). I have a macro loop that goes through and adds the counter to the end of a data set name and that entire string is preceded by 2 ampersands.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Mar 2014 16:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Want-to-check-if-macro-variable-0-as-part-of-if-condition/m-p/148261#M29333</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-03-19T16:44:36Z</dc:date>
    </item>
  </channel>
</rss>

