<?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: Conditionally Set Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581362#M165228</link>
    <description>&lt;P&gt;You can't use normal sas-function ins macro-code, you have to wrap all function in %sysfunc-calls. Also note that quoting string in macro is seldom necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is, as always, a good idea to start without any macro code, so use a data-null-step and call symputx to create macro-variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  lastMonthDate = intnx('month', today(), -1, 'same');
  lastMonthNum = month(lastMonthDate);
  call symputx('lastMonth', lastMonthNum);
run;

%put &amp;amp;=lastMonth;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Aug 2019 10:28:20 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-08-15T10:28:20Z</dc:date>
    <item>
      <title>Conditionally Set Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581361#M165227</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling to find a simple way of conditionally setting a variable to the number of the previous month despite having spent a long time trawling through forum answers and trying to interpret answers so apologies for the schoolboy question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please can someone explain to me why the following code is returning the error "Required operator not found in expression: &amp;amp;x = 0?:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro MonthNumber(x);
	%if &amp;amp;x = 0 %then 12;
	%else Month(Date())-1;
%mend MonthNumber;

%LET MonthNo = Month(Date())-1;
%LET END_DATE = intnx('month',MDY(%MonthNumber(&amp;amp;MonthNo),1,Year(Date())) ,0,'end');&lt;/PRE&gt;&lt;P&gt;Any help is much appreciated,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rowan&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 10:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581361#M165227</guid>
      <dc:creator>RowanB1986</dc:creator>
      <dc:date>2019-08-15T10:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Set Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581362#M165228</link>
      <description>&lt;P&gt;You can't use normal sas-function ins macro-code, you have to wrap all function in %sysfunc-calls. Also note that quoting string in macro is seldom necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is, as always, a good idea to start without any macro code, so use a data-null-step and call symputx to create macro-variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  lastMonthDate = intnx('month', today(), -1, 'same');
  lastMonthNum = month(lastMonthDate);
  call symputx('lastMonth', lastMonthNum);
run;

%put &amp;amp;=lastMonth;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2019 10:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581362#M165228</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-15T10:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Set Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581364#M165229</link>
      <description>&lt;P&gt;Thank you very much Andreas. Things are starting to make a lot more sense!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 10:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Set-Variable/m-p/581364#M165229</guid>
      <dc:creator>RowanB1986</dc:creator>
      <dc:date>2019-08-15T10:36:46Z</dc:date>
    </item>
  </channel>
</rss>

