<?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: SYSMONTH for previous Month and current year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773137#M245547</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx('lastmonth',intnx('month',today(),-1,'b'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro variable &amp;amp;lastmonth now is the first day of the previous month. If you run the above code in October 2021, you get the first day of September 2021. Then you can search for any record with a date in the month that begins with &amp;amp;lastmonth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;
     if intnx('month',date,0,'b')=&amp;amp;lastmonth;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Oct 2021 19:57:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-10-08T19:57:13Z</dc:date>
    <item>
      <title>SYSMONTH for previous Month and current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773136#M245546</link>
      <description>&lt;P&gt;WHERE tran_month&amp;nbsp; = &amp;amp;sysmonth&lt;/P&gt;
&lt;P&gt;This snippet of code will return all transactions for the current month (all October dates regardless of year)&lt;/P&gt;
&lt;P&gt;Is there a way to us the same &amp;amp;sysmonth except use the previous &amp;amp;sysmonth and current year only (in this case I want transactions from 9/1/21 through 9/30/21).&amp;nbsp; I believe the current &amp;amp;sysmonth gives you all transaction in October regardless of the year.&amp;nbsp; I only want the previous month for the current year.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 19:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773136#M245546</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-10-08T19:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: SYSMONTH for previous Month and current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773137#M245547</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx('lastmonth',intnx('month',today(),-1,'b'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Macro variable &amp;amp;lastmonth now is the first day of the previous month. If you run the above code in October 2021, you get the first day of September 2021. Then you can search for any record with a date in the month that begins with &amp;amp;lastmonth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example in a DATA step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;
     if intnx('month',date,0,'b')=&amp;amp;lastmonth;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Oct 2021 19:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773137#M245547</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-08T19:57:13Z</dc:date>
    </item>
    <item>
      <title>UPDATE Re: SYSMONTH for previous Month and current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773149#M245551</link>
      <description>&lt;P&gt;Follow up question&lt;/P&gt;
&lt;P&gt;tran_year1= YEAR(FEE_TRAN_DT) produces a 4 digit year (ie 2021)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tran_month1= MONTH(FEE_TRAN_DT)&lt;/P&gt;
&lt;P&gt;In some cases it produces a single numeric value such as 8,9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to apply your solution using the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call symputx('lastmonth',put(intnx('month',today(),-1),yymmn6.))&lt;/P&gt;
&lt;P&gt;I would need a way to add a leading zeros to the&amp;nbsp;tran_month1= MONTH(FEE_TRAN_DT) then use a cat feature such as&lt;/P&gt;
&lt;P&gt;catx('',tran_year1,tran_month1)&lt;/P&gt;
&lt;P&gt;Is there a way to add the leading zero to the tran_month1 only if it produces a single digit month?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 20:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773149#M245551</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-10-08T20:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: UPDATE Re: SYSMONTH for previous Month and current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773159#M245554</link>
      <description>&lt;P&gt;If you need a leading zero then that means:&lt;/P&gt;
&lt;P&gt;1) you are comparing or using a character variable not date values, which isn't really obvious from your shown bits and likely is a cause of other problems and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Put a numeric value with the Z2. format to make a character value with leading zero if less than two digits:&amp;nbsp; Tran_month1=&amp;nbsp; put (MONTH(FEE_TRAN_DT), Z2.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 21:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773159#M245554</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-08T21:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: UPDATE Re: SYSMONTH for previous Month and current year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773160#M245555</link>
      <description>&lt;P&gt;Don't split year and month and day. You are just making extra work for yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use actual SAS date values, SAS has already done the hard work to deal with calendar dates, so you don't have to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do it the way I showed in my answer above.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 21:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSMONTH-for-previous-Month-and-current-year/m-p/773160#M245555</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-08T21:19:59Z</dc:date>
    </item>
  </channel>
</rss>

