<?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: Dates in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634795#M35728</link>
    <description>thank you for your reply, I will try to apply this logic to my code and will let you know it goes.&lt;BR /&gt;&lt;BR /&gt;thank you again</description>
    <pubDate>Wed, 25 Mar 2020 15:39:26 GMT</pubDate>
    <dc:creator>Ela_84</dc:creator>
    <dc:date>2020-03-25T15:39:26Z</dc:date>
    <item>
      <title>Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634780#M35722</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a field of due days listed as below : How would i calculate in sas eg if due day in (30,31) then last paid date = 29FEB2020.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is the code i wrote :&lt;/P&gt;&lt;P&gt;Data Test;&lt;BR /&gt;Set Test_1;&lt;BR /&gt;Format lastPaiDdate date9.;&lt;/P&gt;&lt;P&gt;if DueDay &amp;gt;= today then lastPaiDdate = (MDY(month-1,DueDay,year));&lt;BR /&gt;else if DueDay &amp;lt; today then lastPaiDdate = (MDY(month,DueDay,year));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table I want to create below :&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;DueDay&lt;/TD&gt;&lt;TD&gt;LastDatePaid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;02-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;03-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29&lt;/TD&gt;&lt;TD&gt;29-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;29-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;31&lt;/TD&gt;&lt;TD&gt;29-Feb-20&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634780#M35722</guid>
      <dc:creator>Ela_84</dc:creator>
      <dc:date>2020-03-25T15:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634782#M35723</link>
      <description>&lt;P&gt;Are we assuming that we only need to write code for February 2020, or do we need the code to be more general to handle other months and non-leap years?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634782#M35723</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-25T15:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634783#M35724</link>
      <description>more general to handle other month and non leap years please.</description>
      <pubDate>Wed, 25 Mar 2020 15:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634783#M35724</guid>
      <dc:creator>Ela_84</dc:creator>
      <dc:date>2020-03-25T15:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634787#M35725</link>
      <description>&lt;P&gt;So, in the program, we'd have to make use a variable that contains the month and year. How would the program know what month and year to do the calculations for? Your example shows only one input variable, and one output variable, neither of which can be used to determine what month and year the calculations should be done for.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634787#M35725</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-25T15:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634788#M35726</link>
      <description>&lt;P&gt;The better function to use for incrementing dates is INTNX.&lt;/P&gt;
&lt;P&gt;You can specify the interval, such as month and indicate whether you want the start, end or same day of the month. And the function takes care of such nasty things as leap years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the end of the previous month for example then the code would look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastmonth = intnx('month',date, -1,'E');&lt;/P&gt;
&lt;P&gt;The interval is the first parameter, the second is the date to start from,your current value, then is the number of intervals to apply, in this case negative 1 to get the last month. The final parameter 'E' says to get the last day of the interval.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't show a value for Today, and the function Today() would almost certainly never be less than DueDay so I can't be sure what you are comparing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of using INTNX with the 'S' alignment, for Same, applied to a date getting the same "day" in the previous month.&lt;/P&gt;
&lt;PRE&gt;data example;
	do date = '25Mar2020'd to '31Mar2020'd;
		prevdate = intnx('month',date,-1,'S');
		output;
	end;
	format date prevdate date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Note that all of 29, 30 and 31 March get mapped to 29 Feb.&lt;/P&gt;
&lt;P&gt;If you change the year in the DO loop to a non-leap year then you would see all of 28 to 31 March mapped to 28 Feb.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634788#M35726</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-25T15:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634792#M35727</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;maybe something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DueDay;
cards;
1
2
3
29
30
31
;
run;

data want;
  month=2;
  year=2020;

  max_day = day(intnx("month", mdy(month, 1, year),0,"end"));

  set have;

  DueDate = mdy(month, max_day&amp;gt;&amp;lt;DueDay, year);
  format DueDate yymmdd10.;
  keep Due:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634792#M35727</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-25T15:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634795#M35728</link>
      <description>thank you for your reply, I will try to apply this logic to my code and will let you know it goes.&lt;BR /&gt;&lt;BR /&gt;thank you again</description>
      <pubDate>Wed, 25 Mar 2020 15:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634795#M35728</guid>
      <dc:creator>Ela_84</dc:creator>
      <dc:date>2020-03-25T15:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634798#M35729</link>
      <description>thanks Bart, I will try this logic and let you know how it goes.&lt;BR /&gt;&lt;BR /&gt;appreciate the response</description>
      <pubDate>Wed, 25 Mar 2020 15:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634798#M35729</guid>
      <dc:creator>Ela_84</dc:creator>
      <dc:date>2020-03-25T15:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634800#M35730</link>
      <description>&lt;P&gt;Use INTNX() to find the last day of the month.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do year=2020;
    do month=1 to 2 ;
      do dueday=27 to 31 ;
         date=input(catx('-',year,month,dueday),??yymmdd10.);
         if missing(date) then date=intnx('month',mdy(month,1,year),0,'e');
         output;
      end;
    end;
  end;
  format date yymmdd10.;
run;
proc print ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    year    month    dueday          date

  1    2020      1        27      2020-01-27
  2    2020      1        28      2020-01-28
  3    2020      1        29      2020-01-29
  4    2020      1        30      2020-01-30
  5    2020      1        31      2020-01-31
  6    2020      2        27      2020-02-27
  7    2020      2        28      2020-02-28
  8    2020      2        29      2020-02-29
  9    2020      2        30      2020-02-29
 10    2020      2        31      2020-02-29
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 15:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634800#M35730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-25T15:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dates</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634803#M35731</link>
      <description>&lt;P&gt;You can do it one statement if you want. Use JANUARY of the same year to make a date that can use any valid dueday. Then use INTNX to offset by the number of months from JANUARY to your target month using the SAME option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=intnx('month',mdy(1,dueday,year),intck('month',mdy(1,1,year),mdy(month,1,year)),'same');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 16:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Dates/m-p/634803#M35731</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-25T16:02:52Z</dc:date>
    </item>
  </channel>
</rss>

