<?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 Subtract month from YYYYMM macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subtract-month-from-YYYYMM-macro-variable/m-p/692356#M210907</link>
    <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and need help with subtracting months from a macro variable storing date in YYYYMM format. I tried the following code but it isn't working, any help on this would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired value for last_mon is 201909&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let score_month = 201910; /*YYYYMM format */
%let mon_var = %sysfunc(inputn(putn(&amp;amp;score_month,6.)!!'01',yymmdd8.)); /*converting to sas date format by adding day as 01 */
%let last_mon = %sysfunc(intnx(month,&amp;amp;mon_var,-1),yymmn6.); /*subtracting 1 month */ 
%put &amp;amp;score_month***&amp;amp;last_mon***&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;Notes :&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 %let score_month = 201910; /*YYYYMM format */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 %let mon_var = %sysfunc(inputn(putn(&amp;amp;score_month,6.)!!'01',yymmdd8.)); /*converting to sas date format by adding day as&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 ! 01 */&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;to a missing value.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 %let last_mon = %sysfunc(intnx(month,&amp;amp;mon_var,-1),yymmn6.); /*subtracting 1 month */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;76 %put &amp;amp;score_month***&amp;amp;last_mon***;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;201910***.***&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;77&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;90&lt;/DIV&gt;</description>
    <pubDate>Sun, 18 Oct 2020 12:17:12 GMT</pubDate>
    <dc:creator>somepathak</dc:creator>
    <dc:date>2020-10-18T12:17:12Z</dc:date>
    <item>
      <title>Subtract month from YYYYMM macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtract-month-from-YYYYMM-macro-variable/m-p/692356#M210907</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and need help with subtracting months from a macro variable storing date in YYYYMM format. I tried the following code but it isn't working, any help on this would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired value for last_mon is 201909&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let score_month = 201910; /*YYYYMM format */
%let mon_var = %sysfunc(inputn(putn(&amp;amp;score_month,6.)!!'01',yymmdd8.)); /*converting to sas date format by adding day as 01 */
%let last_mon = %sysfunc(intnx(month,&amp;amp;mon_var,-1),yymmn6.); /*subtracting 1 month */ 
%put &amp;amp;score_month***&amp;amp;last_mon***&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;Notes :&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 %let score_month = 201910; /*YYYYMM format */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 %let mon_var = %sysfunc(inputn(putn(&amp;amp;score_month,6.)!!'01',yymmdd8.)); /*converting to sas date format by adding day as&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 ! 01 */&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;to a missing value.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 %let last_mon = %sysfunc(intnx(month,&amp;amp;mon_var,-1),yymmn6.); /*subtracting 1 month */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;76 %put &amp;amp;score_month***&amp;amp;last_mon***;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;201910***.***&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;77&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;78 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;90&lt;/DIV&gt;</description>
      <pubDate>Sun, 18 Oct 2020 12:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtract-month-from-YYYYMM-macro-variable/m-p/692356#M210907</guid>
      <dc:creator>somepathak</dc:creator>
      <dc:date>2020-10-18T12:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract month from YYYYMM macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subtract-month-from-YYYYMM-macro-variable/m-p/692358#M210908</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt; ... do not format macro variables for the purpose of performing arithmetic or logical operations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let score_month = 201910; 
%let mon_var = %sysfunc(inputn(&amp;amp;score_month,yymmn6.)); /* Not formatted */
%let last_mon = %sysfunc(intnx(month,&amp;amp;mon_var,-1)); /* Not formatted */
%put &amp;amp;=score_month &amp;amp;=last_mon;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now to see what the integer in &amp;amp;last_mon represents, so humans can understand it, formatting is appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(putn(&amp;amp;last_mon,yymmn6.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Oct 2020 15:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subtract-month-from-YYYYMM-macro-variable/m-p/692358#M210908</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-18T15:50:35Z</dc:date>
    </item>
  </channel>
</rss>

