<?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: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684284#M207343</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your reply. Is that possible to store&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;the date as a numeric value but shown as the date &lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but you would have to choose one format or the other -- or have two separate variables.&amp;nbsp; Let's say we want MM/DD/YYYY to be the default representation.&amp;nbsp; You would change the code like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	DROP	In_Date;
	FORMAT	Start_Date	MMDDYYS10.;

	infile cards truncover;
	input
	In_Date $200.
	;

	Start_Date = INPUT(STRIP(In_Date), ANYDTDTE11.);
	PUTLOG "NOTE:  "    Start_Date=;
	PUTLOG "NOTE-  "    Start_Date= DATE9.;
	PUTLOG "NOTE-  ";
cards;
Dec-24-2020
Feb-11-2020
Apr-13-2018
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if you look at the results, you will see that they appear in MM/DD/YYYY format, but look at the icon.&amp;nbsp; It is a date icon not a character icon.&amp;nbsp; The value is stored internally as a numeric date but is represented in the format we want.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600270652512.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49439i825E59A096002B53/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600270652512.png" alt="jimbarbour_0-1600270652512.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice my log statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	PUTLOG "NOTE:  "    Start_Date=;
	PUTLOG "NOTE-  "    Start_Date= DATE9.;
	PUTLOG "NOTE-  ";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first has no format.&amp;nbsp; Since we applied a default or "permanent" format to Start_Date, the MM/DD/YYYY format will be used.&lt;/P&gt;
&lt;P&gt;However, if we want to display the Start_Date in another format, then we simply specify that format after the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Our log looks like this:&lt;/P&gt;
&lt;PRE&gt;NOTE:  Start_Date=12/24/2020
       Start_Date=24DEC2020
       
NOTE:  Start_Date=02/11/2020
       Start_Date=11FEB2020
       
NOTE:  Start_Date=04/13/2018
       Start_Date=13APR2018&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Wed, 16 Sep 2020 15:46:00 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2020-09-16T15:46:00Z</dc:date>
    <item>
      <title>convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684234#M207319</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to convert text 'MMM-DD-YYYY' (e.g.,&amp;nbsp;Dec-24-2020)&lt;/P&gt;&lt;P&gt;to date 'MM/DD/YYYY' (e.g., '12/24/2020')&lt;/P&gt;&lt;P&gt;and date 'DDMMMYYYY' (e.g., '24DEC2020')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data table1;
	infile cards truncover;
	input
	start_date $200.
	;
	cards;
	Dec-24-2020
	Feb-11-2020
	Apr-13-2018
	;;;;
	run;&lt;/PRE&gt;&lt;P&gt;Could you please give me some suggestions? Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 14:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684234#M207319</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-09-16T14:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684239#M207322</link>
      <description>&lt;P&gt;Something like this perhaps?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	infile cards truncover;
	input
	start_date $200.
	;
	Temp_Date = INPUT(STRIP(start_date), ANYDTDTE11.);
	Date_mmddyyyy = PUT(Temp_Date, MMDDYYS10.);
	Date_ddmmmyyyy = PUT(Temp_Date, DATE9.);
	PUTLOG "NOTE:  "    Date_mmddyyyy= Date_ddmmmyyyy=;
cards;
Dec-24-2020
Feb-11-2020
Apr-13-2018
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRIKE&gt;I haven't double checked my formats yet&lt;/STRIKE&gt;, but this is along the lines of what you would need to do.&lt;/P&gt;
&lt;P&gt;I have now checked my formats and informats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The basic idea is to read in the character date into a numeric SAS date field using the INPUT function and a date informat.&amp;nbsp; Then, by using the PUT function, I can convert the numeric SAS date field into any character format that I want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;INPUT takes character and transforms it to numeric (dates are numeric) using an Informat.&lt;/P&gt;
&lt;P&gt;PUT takes numeric and transforms it to character using a Format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684239#M207322</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T15:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684246#M207327</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;I couldn't find a MMMDDYY informat in the documentation. Is it an undocumented one?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 14:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684246#M207327</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-16T14:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684257#M207332</link>
      <description>&lt;P&gt;No, that's an error.&amp;nbsp; I corrected it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684257#M207332</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T15:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684265#M207336</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data result;
  set table1;
  dateDDMMMYYYY = upcase(catt(scan(start_date,2),scan(start_date,1),scan(start_date,3)));
  realdate = input(dateDDMMMYYYY,Date10.);
  MMDDYYSdate = put(realdate,MMDDYYS10.);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684265#M207336</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-16T15:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684274#M207340</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your reply. Is that possible to store&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;the date as a numeric value but shown as the date &lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684274#M207340</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-09-16T15:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684276#M207341</link>
      <description>&lt;P&gt;Just and a format statement like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data result;
  set table1;
  format realdate Date10.;
  dateDDMMMYYYY = upcase(catt(scan(start_date,2),scan(start_date,1),scan(start_date,3)));
  realdate = input(dateDDMMMYYYY,Date10.);
  MMDDYYSdate = put(realdate,MMDDYYS10.);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684276#M207341</guid>
      <dc:creator>CurtisMackWSIPP</dc:creator>
      <dc:date>2020-09-16T15:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684284#M207343</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your reply. Is that possible to store&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;the date as a numeric value but shown as the date &lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but you would have to choose one format or the other -- or have two separate variables.&amp;nbsp; Let's say we want MM/DD/YYYY to be the default representation.&amp;nbsp; You would change the code like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	DROP	In_Date;
	FORMAT	Start_Date	MMDDYYS10.;

	infile cards truncover;
	input
	In_Date $200.
	;

	Start_Date = INPUT(STRIP(In_Date), ANYDTDTE11.);
	PUTLOG "NOTE:  "    Start_Date=;
	PUTLOG "NOTE-  "    Start_Date= DATE9.;
	PUTLOG "NOTE-  ";
cards;
Dec-24-2020
Feb-11-2020
Apr-13-2018
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, if you look at the results, you will see that they appear in MM/DD/YYYY format, but look at the icon.&amp;nbsp; It is a date icon not a character icon.&amp;nbsp; The value is stored internally as a numeric date but is represented in the format we want.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600270652512.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49439i825E59A096002B53/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600270652512.png" alt="jimbarbour_0-1600270652512.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice my log statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	PUTLOG "NOTE:  "    Start_Date=;
	PUTLOG "NOTE-  "    Start_Date= DATE9.;
	PUTLOG "NOTE-  ";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first has no format.&amp;nbsp; Since we applied a default or "permanent" format to Start_Date, the MM/DD/YYYY format will be used.&lt;/P&gt;
&lt;P&gt;However, if we want to display the Start_Date in another format, then we simply specify that format after the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Our log looks like this:&lt;/P&gt;
&lt;PRE&gt;NOTE:  Start_Date=12/24/2020
       Start_Date=24DEC2020
       
NOTE:  Start_Date=02/11/2020
       Start_Date=11FEB2020
       
NOTE:  Start_Date=04/13/2018
       Start_Date=13APR2018&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684284#M207343</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T15:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: convert text 'MMM-DD-YYYY' to date 'MM/DD/YYYY' and  'DDMMMYYYY'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684307#M207354</link>
      <description>&lt;P&gt;Oh,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I should mention one more thing:&amp;nbsp; The&amp;nbsp;ANYDTDTE11. format is a wonderful format,&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;but&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;you have to be a little bit careful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, consider this date:&lt;/P&gt;
&lt;P&gt;08/09/2020&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that August 9th or is that September 8th?&amp;nbsp; In the US, that would be August 9th.&amp;nbsp; In Europe, typically, that would be September 8th.&amp;nbsp; Your DATESTYLE and LOCALE settings determine whether a date will be interpreted as MM/DD/YYYY or DD/MM/YYYY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;has an excellent blog post on the subject:&amp;nbsp;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2016/11/11/anydtdte-informat-read-any-date-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/11/11/anydtdte-informat-read-any-date-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 16:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-text-MMM-DD-YYYY-to-date-MM-DD-YYYY-and-DDMMMYYYY/m-p/684307#M207354</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-16T16:23:06Z</dc:date>
    </item>
  </channel>
</rss>

