<?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: How to get last day of previous month and first day for current for Decommission and Commission in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835740#M330423</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421594"&gt;@WaiLoon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I finally get it works, so date and datetime having different handling... it is very different from the normal SQL...&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Normal SQL typically only has datetime fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Sep 2022 01:42:55 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-09-29T01:42:55Z</dc:date>
    <item>
      <title>How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833100#M329323</link>
      <description>&lt;P&gt;Equipment Data&lt;BR /&gt;Voltage&lt;BR /&gt;Master Project&lt;BR /&gt;AIPM workflow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Hoza by BA level&lt;BR /&gt;User access by State/Hoza/BA&lt;/P&gt;&lt;P&gt;GIS Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;My program getting hardware list from another system, but the system don't have CommissionDate and DecommissionDate. Source system is in Excel and Target is PostgreSQL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore I need to generate these 2 value every month when ETL the hardware list.&lt;/P&gt;&lt;P&gt;So, what I planned to do is, if the hardware from source DB not in the target DB, then I will insert and set the CommissionDate to 1st of current month.&lt;/P&gt;&lt;P&gt;If the hardware in target DB not in source DB, then I will set the DecommissionDate to last day of previous month.&lt;/P&gt;&lt;P&gt;I tried many way but unfortunately can't get it work. I can't even get the previous month work.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But today I tried this&lt;BR /&gt;%let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), yymmdd8.);&lt;BR /&gt;%put &amp;amp;Decomm;&lt;BR /&gt;&lt;BR /&gt;And I get&lt;BR /&gt;276 %let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), yymmdd8.);&lt;BR /&gt;277 %put &amp;amp;Decomm;&lt;BR /&gt;SYMBOLGEN: Macro variable DECOMM resolves to 22-08-13&lt;BR /&gt;22-08-13&lt;/P&gt;&lt;P&gt;it seems like is I manage to get previous month, but I need the day to be last day of the month and also the format should be dd/mm/yyyy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today I tried this syntax&lt;/P&gt;&lt;P&gt;%let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), ddmmyyyy8.);&lt;BR /&gt;%put &amp;amp;Decomm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I get this&lt;/P&gt;&lt;P&gt;276 %let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), ddmmyyyy8.);&lt;BR /&gt;277 %put &amp;amp;Decomm;&lt;BR /&gt;SYMBOLGEN: Macro variable DECOMM resolves to 22870&lt;BR /&gt;22870&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Other than above, i also need to get the first day of current month...&lt;/P&gt;&lt;P&gt;May I know what is my script missed??&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833100#M329323</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-13T12:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833101#M329324</link>
      <description>&lt;P&gt;INTNX has several choices for the final option. Instead of &lt;FONT face="courier new,courier"&gt;same&lt;/FONT&gt;, you can use &lt;FONT face="courier new,courier"&gt;end&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;beginning&lt;/FONT&gt;. That will get you the desired end of month date or beginning of month date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Today I tried this syntax&lt;/P&gt;
&lt;P&gt;%let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), ddmmyyyy8.);&lt;BR /&gt;%put &amp;amp;Decomm;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I get this&lt;/P&gt;
&lt;P&gt;276 %let Decomm=%sysfunc(intnx(month,%sysfunc(today()),-1,same), ddmmyyyy8.);&lt;BR /&gt;277 %put &amp;amp;Decomm;&lt;BR /&gt;SYMBOLGEN: Macro variable DECOMM resolves to 22870&lt;BR /&gt;22870&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should see an ERROR in the log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Format name DDMMYYYY8. not found or the width and/or decimal specified for the format used are out of range.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't ignore errors like this. It is telling you important information. It is telling you that you are trying to use a format name that doesn't exist. The format you should use is DDMMYY8.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833101#M329324</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T12:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833118#M329330</link>
      <description>&lt;P&gt;Use INTNX with correct parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let first_day_curr_month = %sysfunc(intnx(month,%sysfunc(today()),0,b));
%let last_day_prev_month = %eval(&amp;amp;first_day_curr_month. - 1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need the values in assignments and calculations, don't bother with formatting them, see Maxim 28.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 13:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833118#M329330</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-13T13:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833141#M329334</link>
      <description>Thanks. But what if I need to have yyyy, how should I format??</description>
      <pubDate>Tue, 13 Sep 2022 14:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833141#M329334</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-13T14:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833147#M329337</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421594"&gt;@WaiLoon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks. But what if I need to have yyyy, how should I format??&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please try &lt;SPAN&gt;DDMMYY10&lt;/SPAN&gt;. it will give you a four digit year.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/833147#M329337</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-13T14:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835118#M330134</link>
      <description>&lt;P&gt;Hi, thanks for suggestions, and sorry for the late reply cause suddenly got some production issue need to resolve.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the suggested syntax but still not able to get correct date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let first_day_curr_month = %sysfunc(intnx(month,%sysfunc(today()),0,b));&lt;BR /&gt;%let last_day_prev_month = %eval(&amp;amp;first_day_curr_month. -1);&lt;/P&gt;&lt;P&gt;UPDATE HardwareList tgt&lt;BR /&gt;SET DateDecommissioned = &amp;amp;last_day_prev_month&lt;/P&gt;&lt;P&gt;WHERE NOT EXISTS (.......);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I check the data, the&amp;nbsp;DateDecommissioned&amp;nbsp; is&amp;nbsp;1960-01-01 06:21:28&lt;/P&gt;&lt;P&gt;Anything i did wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 08:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835118#M330134</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-26T08:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835123#M330137</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421594"&gt;@WaiLoon&lt;/a&gt;&amp;nbsp;Not that I see that anywhere in the code you've shared BUT... SAS got DATE and DATETIME values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A SAS Date value is the count of days since 1/1/1960, a SAS DateTime value is the count of seconds since 1/1/1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time if you get something like&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;DateDecommissioned&amp;nbsp; is&amp;nbsp;1960-01-01 06:21:28&lt;/EM&gt; it's an indication that you've used a SAS DateTime FORMAT to print a SAS Date value (=prints your count of days as if it were a count of seconds).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 09:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835123#M330137</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-26T09:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835161#M330157</link>
      <description>So your target variable is datetime, not a date.&lt;BR /&gt;Change the assignment:&lt;BR /&gt;&lt;BR /&gt;%let first_day_curr_month = %sysfunc(intnx(dtmonth,%sysfunc(datetime()),0,b));&lt;BR /&gt;%let last_day_prev_month = %eval(&amp;amp;first_day_curr_month. -1);</description>
      <pubDate>Mon, 26 Sep 2022 13:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835161#M330157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-26T13:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835738#M330422</link>
      <description>&lt;P&gt;I finally get it works, so date and datetime having different handling... it is very different from the normal SQL...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 01:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835738#M330422</guid>
      <dc:creator>WaiLoon</dc:creator>
      <dc:date>2022-09-29T01:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835740#M330423</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/421594"&gt;@WaiLoon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I finally get it works, so date and datetime having different handling... it is very different from the normal SQL...&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Normal SQL typically only has datetime fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 01:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835740#M330423</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-29T01:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get last day of previous month and first day for current for Decommission and Commission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835744#M330425</link>
      <description>&lt;P&gt;There is no "normal" SQL. Different database systems handle dates and times differently.&lt;/P&gt;
&lt;P&gt;For instance, IBM's DB/2 treats them exactly like SAS, as counts of days and counts of seconds, respectively.&lt;/P&gt;
&lt;P&gt;(This allows to store dates in 4 bytes as default)&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 01:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-last-day-of-previous-month-and-first-day-for-current/m-p/835744#M330425</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-29T01:51:37Z</dc:date>
    </item>
  </channel>
</rss>

