<?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 SYSDATE to get first and last day of last year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625140#M184234</link>
    <description>&lt;P&gt;I began with the following data _null_ to attempt to get todays date in yymmdd10&amp;nbsp; (ie '2020-02-16')&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_NULL_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SYMPUTx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'DEKEY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;|| PUT(INTNX(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'DAY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;sysdate9,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'END'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymmddd10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) ||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;RUN&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;dekey;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am attempting to get the first and last day of last year using the sysdate function&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(ie '2019-01-01'&amp;nbsp; and then a separate data _null for '2019-12-31')&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Feb 2020 20:58:59 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2020-02-16T20:58:59Z</dc:date>
    <item>
      <title>SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625140#M184234</link>
      <description>&lt;P&gt;I began with the following data _null_ to attempt to get todays date in yymmdd10&amp;nbsp; (ie '2020-02-16')&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_NULL_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CALL&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SYMPUTx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'DEKEY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;|| PUT(INTNX(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'DAY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;sysdate9,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'END'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymmddd10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) ||&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"'"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;RUN&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;dekey;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am attempting to get the first and last day of last year using the sysdate function&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(ie '2019-01-01'&amp;nbsp; and then a separate data _null for '2019-12-31')&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 20:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625140#M184234</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-02-16T20:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625141#M184235</link>
      <description>&lt;P&gt;It would be easier using the TODAY() function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    call symputx('begin',intnx('year',today(),0,'b');
    call symputx('end',intnx('year',today(),0,'e');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Feb 2020 21:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625141#M184235</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-16T21:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625142#M184236</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp; If you are referring to SYSDATE automatic macro variable as a date from today, I am afraid you may get unexpected results as sysdate c&lt;SPAN&gt;ontains the date on which a SAS job or session began executing and not really today's date.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if the above seems to make sense, you can use&lt;STRONG&gt; Today()&lt;/STRONG&gt; function&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;

CALL SYMPUTx('last_date',put(intnx('year',today(),-1,'e'),yymmdd10.),'g') ;
CALL SYMPUTx('first_date',put(intnx('year',today(),-1,'b'),yymmdd10.),'g') ;

RUN;

%put &amp;amp;=last_date;
%put &amp;amp;=first_date;
LOG:

1476  %put &amp;amp;=last_date;
LAST_DATE=2019-12-31
1477  %put &amp;amp;=first_date;
FIRST_DATE=2019-01-01
&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, 16 Feb 2020 21:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625142#M184236</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-16T21:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625143#M184237</link>
      <description>&lt;P&gt;Comment: it usually is not necessary to format a macro variable, because to make use of it (except in titles or labels), you will have to un-format it later. So just leave it unformatted.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 21:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625143#M184237</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-16T21:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625144#M184238</link>
      <description>&lt;P&gt;Fully agree. I did think of it, and I did un-think of it to offer just what the OP mentioned.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 21:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625144#M184238</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-16T21:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: SYSDATE to get first and last day of last year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625176#M184248</link>
      <description>&lt;P&gt;The is no SYSDATE function. There is a SYSDATE macro variable (But it is much better to use the SYSDATE9 macro variable instead since it has all four digits of the year.) If you want to use the SYSDATE9 macro variable as a date then you need to convert it to an actual date by use date literal syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;sysdate9"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that SYSDATE9 macro variable is set when your SAS session starts.&amp;nbsp; If you want the current date then use the DATE() function instead, or its alias TODAY().&lt;/P&gt;
&lt;P&gt;If you want to move the first (or last) day of the year use the YEAR interval.(NOTE&amp;nbsp; It is not necessary to use the DAY interval for dates since they are already stored as a count of days, you can just use math.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could just find the YEAR and use MDY() with 1,1 or 12,31 for the M and D .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  now=date();
  first_day = mdy(1,1,year(now));
  last_day= mdy(12,31,year(now));
  call symputx('first_day',quote(put(first_day,yymmdd10.),"'"));
  call symputx('last_day',quote(put(last_day,yymmdd10.),"'"));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Feb 2020 02:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SYSDATE-to-get-first-and-last-day-of-last-year/m-p/625176#M184248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-17T02:53:41Z</dc:date>
    </item>
  </channel>
</rss>

