<?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 Given year and month, how to formate a date variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Given-year-and-month-how-to-formate-a-date-variable/m-p/533850#M146423</link>
    <description>&lt;P&gt;In my sample of data, I have firm, year, month and price variables. I would like to create a new variable with year-month-day in any sas format, where day is the last business day (or last day) of the given year month. Can anyone help me on it plz? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tmp1;&lt;BR /&gt;input year firm$ month$ price;&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;2004 AE0006 m1 8.2&lt;BR /&gt;2004 AE0006 m2 8.5&lt;BR /&gt;2004 AE0006 m3 8.2&lt;BR /&gt;2004 AE0006 m4 8.3&lt;BR /&gt;2004 AE0006 m5 8.4&lt;BR /&gt;2004 AE0006 m6 8.5&lt;BR /&gt;2004 AE0006 m7 8.6&lt;BR /&gt;2004 AE0006 m8 8.7&lt;BR /&gt;2004 AE0006 m9 8.8&lt;BR /&gt;2004 AE0006 m10 8.9&lt;BR /&gt;2004 AE0006 m11 9&lt;BR /&gt;2004 AE0006 m12 9.1&lt;BR /&gt;2005 AE0006 m1 9.2&lt;BR /&gt;2005 AE0006 m2 9.3&lt;BR /&gt;2005 AE0006 m3 9.4&lt;BR /&gt;2005 AE0006 m4 9.5&lt;BR /&gt;2005 AE0006 m5 9.6&lt;BR /&gt;2005 AE0006 m6 9.7&lt;BR /&gt;2005 AE0006 m7 9.8&lt;BR /&gt;2005 AE0006 m8 9.9&lt;BR /&gt;2005 AE0006 m9 10&lt;BR /&gt;2005 AE0006 m10 10.1&lt;BR /&gt;2005 AE0006 m11 10.2&lt;BR /&gt;2005 AE0006 m12 10.3&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I expect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price&lt;BR /&gt;31-Jan-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.2&lt;BR /&gt;29-Feb-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.5&lt;BR /&gt;31-Mar-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.2&lt;BR /&gt;30-Apr-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.3&lt;BR /&gt;31-May-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.4&lt;BR /&gt;30-Jun-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.5&lt;BR /&gt;31-Jul-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.6&lt;BR /&gt;31-Aug-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.7&lt;BR /&gt;30-Sep-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.8&lt;BR /&gt;31-Oct-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.9&lt;BR /&gt;30-Nov-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;BR /&gt;31-Dec-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.1&lt;BR /&gt;31-Jan-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.2&lt;BR /&gt;28-Feb-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.3&lt;BR /&gt;31-Mar-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.4&lt;BR /&gt;30-Apr-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.5&lt;BR /&gt;31-May-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.6&lt;BR /&gt;30-Jun-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.7&lt;BR /&gt;31-Jul-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.8&lt;BR /&gt;31-Aug-2005 &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.9&lt;BR /&gt;30-Sep-2005 &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;31-Oct-2005 &amp;nbsp; &amp;nbsp; 10.1&lt;BR /&gt;30-Nov-2005 &amp;nbsp; &amp;nbsp; 10.2&lt;BR /&gt;31-Dec-2005 &amp;nbsp; &amp;nbsp; 10.3&lt;/P&gt;</description>
    <pubDate>Fri, 08 Feb 2019 05:51:28 GMT</pubDate>
    <dc:creator>Elaine_S</dc:creator>
    <dc:date>2019-02-08T05:51:28Z</dc:date>
    <item>
      <title>Given year and month, how to formate a date variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-year-and-month-how-to-formate-a-date-variable/m-p/533850#M146423</link>
      <description>&lt;P&gt;In my sample of data, I have firm, year, month and price variables. I would like to create a new variable with year-month-day in any sas format, where day is the last business day (or last day) of the given year month. Can anyone help me on it plz? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data tmp1;&lt;BR /&gt;input year firm$ month$ price;&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;2004 AE0006 m1 8.2&lt;BR /&gt;2004 AE0006 m2 8.5&lt;BR /&gt;2004 AE0006 m3 8.2&lt;BR /&gt;2004 AE0006 m4 8.3&lt;BR /&gt;2004 AE0006 m5 8.4&lt;BR /&gt;2004 AE0006 m6 8.5&lt;BR /&gt;2004 AE0006 m7 8.6&lt;BR /&gt;2004 AE0006 m8 8.7&lt;BR /&gt;2004 AE0006 m9 8.8&lt;BR /&gt;2004 AE0006 m10 8.9&lt;BR /&gt;2004 AE0006 m11 9&lt;BR /&gt;2004 AE0006 m12 9.1&lt;BR /&gt;2005 AE0006 m1 9.2&lt;BR /&gt;2005 AE0006 m2 9.3&lt;BR /&gt;2005 AE0006 m3 9.4&lt;BR /&gt;2005 AE0006 m4 9.5&lt;BR /&gt;2005 AE0006 m5 9.6&lt;BR /&gt;2005 AE0006 m6 9.7&lt;BR /&gt;2005 AE0006 m7 9.8&lt;BR /&gt;2005 AE0006 m8 9.9&lt;BR /&gt;2005 AE0006 m9 10&lt;BR /&gt;2005 AE0006 m10 10.1&lt;BR /&gt;2005 AE0006 m11 10.2&lt;BR /&gt;2005 AE0006 m12 10.3&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I expect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; price&lt;BR /&gt;31-Jan-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.2&lt;BR /&gt;29-Feb-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.5&lt;BR /&gt;31-Mar-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.2&lt;BR /&gt;30-Apr-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.3&lt;BR /&gt;31-May-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.4&lt;BR /&gt;30-Jun-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.5&lt;BR /&gt;31-Jul-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.6&lt;BR /&gt;31-Aug-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.7&lt;BR /&gt;30-Sep-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.8&lt;BR /&gt;31-Oct-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 8.9&lt;BR /&gt;30-Nov-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;BR /&gt;31-Dec-2004 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.1&lt;BR /&gt;31-Jan-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.2&lt;BR /&gt;28-Feb-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.3&lt;BR /&gt;31-Mar-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.4&lt;BR /&gt;30-Apr-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.5&lt;BR /&gt;31-May-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.6&lt;BR /&gt;30-Jun-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.7&lt;BR /&gt;31-Jul-2005 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.8&lt;BR /&gt;31-Aug-2005 &amp;nbsp; &amp;nbsp;&amp;nbsp; 9.9&lt;BR /&gt;30-Sep-2005 &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;31-Oct-2005 &amp;nbsp; &amp;nbsp; 10.1&lt;BR /&gt;30-Nov-2005 &amp;nbsp; &amp;nbsp; 10.2&lt;BR /&gt;31-Dec-2005 &amp;nbsp; &amp;nbsp; 10.3&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 05:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-year-and-month-how-to-formate-a-date-variable/m-p/533850#M146423</guid>
      <dc:creator>Elaine_S</dc:creator>
      <dc:date>2019-02-08T05:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Given year and month, how to formate a date variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Given-year-and-month-how-to-formate-a-date-variable/m-p/533889#M146431</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tmp1;
  last_date=intnx('month',mdy(input(substr(month,2),2.),1,year),0,'E');
  select(weekday(last_date));
    when(1) last_working_day=last_date-2; /* Sunday */
    when(7) last_working_day=last_date-1; /* Saturday */
    otherwise last_working_day=last_date;
    end;
  format last_date last_working_day date9.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You wrote that you want the last business date - I put in a check for the weekday, and put the result in last_working_day. But you may have to check for some national holidays as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 12:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Given-year-and-month-how-to-formate-a-date-variable/m-p/533889#M146431</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-02-08T12:14:28Z</dc:date>
    </item>
  </channel>
</rss>

