<?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: subtracting 1 month from the yearmonth value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944500#M370057</link>
    <description>&lt;P&gt;Why not just leave them as DATE values and attach format to print the values in that YYYYMM style?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
  set want;
  new_dt = active_dt ;
  old_dt = intnx('month',active_dt,-1);
  format new_dt old_dt yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really need to create those integers in the YYY,YMM style then remember that the INTNX() interval MONTH works with DATE values.&amp;nbsp; Since you seem to have a date valued variable (otherwise the DATE9 format would print the values as gibberish) just use that variable with your INTNX() call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
  set want;
  new_dt = input(put(active_dt,yymmn6.),6.);
  old_dt = input(put(intnx('month',active_dt,-1),yymmn6.),6.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only have the YYY,YMM integers then convert them into date values first.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;185  data test;
186    new_dt=202403;
187    date_value=input(put(new_dt,z6.),yymmn6.);
188    format date_value yymmdd10.;
189    put (_all_) (=);
190  run;

new_dt=202403 date_value=2024-03-01
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 19:33:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-09-18T19:33:19Z</dc:date>
    <item>
      <title>subtracting 1 month from the yearmonth value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944497#M370055</link>
      <description>&lt;P&gt;I have a data value in the format date9. which I am converting to yymmn6. and need to subtract 1 month from the yymmn6. value and tried below code.&amp;nbsp; Can someone please correct where we need correction in the code. As I am getting unexpected values under old_dt column&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data two;
	set want;
	new_dt = input(put(active_dt,yymmn6.),6.);
	old_dt = intnx('month',new_dt,-1);
run;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="results.JPG" style="width: 172px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100496i65930285C291C8A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="results.JPG" alt="results.JPG" /&gt;&lt;/span&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Sep 2024 19:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944497#M370055</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2024-09-18T19:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting 1 month from the yearmonth value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944499#M370056</link>
      <description>&lt;P&gt;What format have you assigned to the Old_dt variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally if Active_dt is a date value this should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data two;
	set want;
	old_dt = intnx('month',active_dt,-1);
       format old_dt yymmn6. ;
run;
&lt;/PRE&gt;
&lt;P&gt;When you have a date value no reason to recalculate just change the format for some step you need a different appearance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any code that looks like Input (put(datevariable, format.), informat.) is a waste of coding effort.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 19:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944499#M370056</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-18T19:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: subtracting 1 month from the yearmonth value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944500#M370057</link>
      <description>&lt;P&gt;Why not just leave them as DATE values and attach format to print the values in that YYYYMM style?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
  set want;
  new_dt = active_dt ;
  old_dt = intnx('month',active_dt,-1);
  format new_dt old_dt yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really need to create those integers in the YYY,YMM style then remember that the INTNX() interval MONTH works with DATE values.&amp;nbsp; Since you seem to have a date valued variable (otherwise the DATE9 format would print the values as gibberish) just use that variable with your INTNX() call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
  set want;
  new_dt = input(put(active_dt,yymmn6.),6.);
  old_dt = input(put(intnx('month',active_dt,-1),yymmn6.),6.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only have the YYY,YMM integers then convert them into date values first.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;185  data test;
186    new_dt=202403;
187    date_value=input(put(new_dt,z6.),yymmn6.);
188    format date_value yymmdd10.;
189    put (_all_) (=);
190  run;

new_dt=202403 date_value=2024-03-01
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 19:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subtracting-1-month-from-the-yearmonth-value/m-p/944500#M370057</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-18T19:33:19Z</dc:date>
    </item>
  </channel>
</rss>

