<?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 Date Format troubles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423203#M104042</link>
    <description>&lt;P&gt;I am attempting to change dates from a format of "January 2017" to 01/01/2017 and so on. I created a custom format below that is more of a quick fix. But I need to have a format be dynamic such that when 2018 comes around, it will apply to that as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;


proc format;
  value $new_date 'January 2017'= '01/01/2017'
                  'February 2017'= '02/01/2017'
				  'March 2017'= '03/01/2017'
				  'April 2017'= '04/01/2017'
				  'May 2017'= '05/01/2017'
				  'June 2017'= '06/01/2017'
				  'July 2017'= '07/01/2017'
				  'August 2017'= '08/01/2017'
				  'September 2017'= '09/01/2017'
				  'October 2017'= '10/01/2017'
				  'November 2017'= '11/01/2017'
				  'December 2017'= '12/01/2017';
run;

data x;
  set dummy2;
  format Date $new_date.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Dec 2017 19:48:47 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2017-12-21T19:48:47Z</dc:date>
    <item>
      <title>Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423203#M104042</link>
      <description>&lt;P&gt;I am attempting to change dates from a format of "January 2017" to 01/01/2017 and so on. I created a custom format below that is more of a quick fix. But I need to have a format be dynamic such that when 2018 comes around, it will apply to that as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;


proc format;
  value $new_date 'January 2017'= '01/01/2017'
                  'February 2017'= '02/01/2017'
				  'March 2017'= '03/01/2017'
				  'April 2017'= '04/01/2017'
				  'May 2017'= '05/01/2017'
				  'June 2017'= '06/01/2017'
				  'July 2017'= '07/01/2017'
				  'August 2017'= '08/01/2017'
				  'September 2017'= '09/01/2017'
				  'October 2017'= '10/01/2017'
				  'November 2017'= '11/01/2017'
				  'December 2017'= '12/01/2017';
run;

data x;
  set dummy2;
  format Date $new_date.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 19:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423203#M104042</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-12-21T19:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423205#M104044</link>
      <description>&lt;P&gt;Probably a better way, but here's a one-liner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;realdate = input(catt (substr(date,1,3), scan(date,2,' ')),monyy7.);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Full test:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;

data intoDates;
  set dummy2;
  length realdate 8;
  format realdate mmddyy10.;
  realdate = input(catt (substr(date,1,3), scan(date,2,' ')),monyy7.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 20:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423205#M104044</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-12-21T20:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423206#M104045</link>
      <description>&lt;P&gt;some fun to play with functions and not formats:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dummy2;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input Date $14.;&lt;BR /&gt;cards;&lt;BR /&gt;January 2017&lt;BR /&gt;February 2017&lt;BR /&gt;March 2017&lt;BR /&gt;April 2017&lt;BR /&gt;May 2017&lt;BR /&gt;June 2017&lt;BR /&gt;July 2017&lt;BR /&gt;August 2017&lt;BR /&gt;September 2017&lt;BR /&gt;October 2017&lt;BR /&gt;November 2017&lt;BR /&gt;December 2017&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set dummy2;&lt;BR /&gt;new_date=put(input(cats('01',substr(date, 1,3), scan(Date,-1)),date9.),mmddyy10.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;My apologies if mine duplicates your solution. I honestly didn;t see it posted before i posted mine,&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 20:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423206#M104045</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-21T20:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423207#M104046</link>
      <description>&lt;P&gt;Nope&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;- we arrived pretty much at the same time, with similar approaches.&amp;nbsp; Great minds and all...&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 20:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423207#M104046</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-12-21T20:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423212#M104047</link>
      <description>&lt;P&gt;And an example of how to do this with a custom INFORMAT, which is think does what you intended. Note that INVALUE is used to read text into a numeric and assign the date literal in the 'ddMONyyyy'd notation.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
  invalue new_date 
'January 2017'  = '01JAN2017'd
'February 2017' = '01FEB2017'd
'March 2017'    = '01MAR2017'd
'April 2017'    = '01APR2017'd
'May 2017'      = '01MAY2017'd
'June 2017'     = '01JUN2017'd
'July 2017'     = '01JUL2017'd
'August 2017'   = '01AUG2017'd
'September 2017'= '01SEP2017'd
'October 2017'  = '01OCT2017'd
'November 2017' = '01NOV2017'd
'December 2017' = '01DEC2017'd
;
run;


data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  sasdate = input(date,new_date.);
  format sasdate mmddyy10.;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;
&lt;/PRE&gt;
&lt;P&gt;Much lest flexible but the example may be helpful if you get a different set of "months" such that the MONYY. format wouldn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 20:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423212#M104047</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-21T20:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423230#M104051</link>
      <description>&lt;P&gt;Building on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;solution, you don't need to create a format manually, it can be dynamically data driven if you use a CNTLIN data set to create the format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of building a custom informat that works with his example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_format;
*set format name and type;
retain fmtname 'monyearc_fmt' type 'I';

*loop through desired years;
do year=2010 to 2020;
    *loop through each month for each year;
    do month=1 to 12;
        * create date variable desired;
        label = mdy(month, 1, year); 
        *Create left hand side of format using formats;
        start = catx(" ", put(label, monname.), put(label, year4.)); 
        *output records to final data set;
        output;
    end;
end;


run;

*create format from dataset above;
proc format cntlin=date_format;
run;

data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  sasdate = input(date,monyearc_fmt.);
  format sasdate mmddyy10.;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You *could* keep it as a character format if you wanted, but then you look some of the flexibility of having a SAS date. It would require changing the TYPE variable as well as the label value to be character instead of a SAS date as presented. The only advantage to this approach would be your pre-existing code would work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 22:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423230#M104051</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-21T22:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Date Format troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423315#M104082</link>
      <description>&lt;P&gt;If you have sas 9.4, you could try&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data dummy2;
  infile datalines;
  length Date $14.;
  input Date 1-14;
  sasdate = input('1 '||date,anydtdte32.);
  format sasdate mmddyy10.;
  cards;
January 2017
February 2017
March 2017
April 2017
May 2017
June 2017
July 2017
August 2017
September 2017
October 2017
November 2017
December 2017
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Dec 2017 14:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Format-troubles/m-p/423315#M104082</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-22T14:07:16Z</dc:date>
    </item>
  </channel>
</rss>

