<?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: String to Date (mmddyy) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871693#M344396</link>
    <description>&lt;P&gt;Your first option appears to work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input old_date $;
new_date = input(old_date, mmddyy6.);
format new_date date9.;
cards;
040623
033023
040623
;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Reeza_0-1682363577957.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83106iCAB70445B3B25ABD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Reeza_0-1682363577957.png" alt="Reeza_0-1682363577957.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439355"&gt;@jmmedina252&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a string that is mmddyy (example:043023) that I'm having trouble converting to date.&amp;nbsp; I have tried these functions and they have not worked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;old_date&lt;/P&gt;
&lt;P&gt;040623&lt;/P&gt;
&lt;P&gt;033023&lt;/P&gt;
&lt;P&gt;040623&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYY6.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYYN6.);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2023 19:13:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-04-24T19:13:08Z</dc:date>
    <item>
      <title>String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871687#M344393</link>
      <description>&lt;P&gt;I have a string that is mmddyy (example:043023) that I'm having trouble converting to date.&amp;nbsp; I have tried these functions and they have not worked:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;old_date&lt;/P&gt;&lt;P&gt;040623&lt;/P&gt;&lt;P&gt;033023&lt;/P&gt;&lt;P&gt;040623&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYY6.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYYN6.);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871687#M344393</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-04-24T19:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871689#M344394</link>
      <description>&lt;P&gt;What do you mean by "they have not worked"?&amp;nbsp; Are you getting log messages with notes or error messages to that effect?&amp;nbsp; Is the log quiet, but the resulting value is not as expected? if so, what did you get that was unexpected?.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871689#M344394</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-04-24T19:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871693#M344396</link>
      <description>&lt;P&gt;Your first option appears to work for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input old_date $;
new_date = input(old_date, mmddyy6.);
format new_date date9.;
cards;
040623
033023
040623
;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Reeza_0-1682363577957.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83106iCAB70445B3B25ABD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Reeza_0-1682363577957.png" alt="Reeza_0-1682363577957.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439355"&gt;@jmmedina252&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a string that is mmddyy (example:043023) that I'm having trouble converting to date.&amp;nbsp; I have tried these functions and they have not worked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;old_date&lt;/P&gt;
&lt;P&gt;040623&lt;/P&gt;
&lt;P&gt;033023&lt;/P&gt;
&lt;P&gt;040623&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYY6.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;new_date = input(old_date,MMDDYYN6.);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871693#M344396</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-24T19:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871694#M344397</link>
      <description>&lt;P&gt;Is old-date really of type character, or a number without a date format?&lt;/P&gt;
&lt;P&gt;If character, remove leading blanks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = input(left(old_date),MMDDYY6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And do not forget to assign a date format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format new_date yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you still have trouble, please post the complete (all code and messages) log of your conversion step.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871694#M344397</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-24T19:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871695#M344398</link>
      <description>&lt;P&gt;There are several things we would need to know in order to give you a definitive answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing is whether this variable called OLD_DATE is numeric or character. Please let us know. Another thing we would need to know is the appearance of the variable (you have shown us that) and the appearance unformatted (please show us that).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given all these things, we can then give you a definitive answer. Without the above information, we're guessing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, there is no such informat as &lt;SPAN&gt;MMDDYYN6. There is an informat&amp;nbsp;MMDDYY6. which will work only on character variables, one reason why we need to know if OLD_DATE is numeric or character. Finally, do not show us partial code. Be generous, if you can't get a DATA step to work, show us the entire DATA step and the entire LOG for that data step.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 19:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871695#M344398</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-24T19:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: String to Date (mmddyy)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871756#M344426</link>
      <description>&lt;P&gt;If OLD_DATE is character (and does not have leading spaces) then you can convert it with the MMDDYY6 informat and get a pretty good estimate of the date (depending on whether your dates might be more than 80 years old or not).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input old_date $6. ;
cards;
040623
033023
040623
;
data want;
  set have;
  new_date = input(old_date,mmddyy6.);
  format new_date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;OBS    old_date      new_date

 1      040623     2023-04-06
 2      033023     2023-03-30
 3      040623     2023-04-06
&lt;/PRE&gt;
&lt;P&gt;If OLD_DATE is a numeric variable that is using the Z6. format to display so that the leading zeros appear then you will first need to convert it to a character string before using the INPUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input old_date ;
  format old_date z6.;
cards;
040623
033023
040623
;
data want;
  set have;
  new_date = input(put(old_date,z6.),mmddyy6.);
  format new_date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;OBS    old_date      new_date

 1      040623     2023-04-06
 2      033023     2023-03-30
 3      040623     2023-04-06
&lt;/PRE&gt;
&lt;P&gt;And if OLD_DATE is already a DATE value, but is using the MMDDYY6. format to display only six digits then you don't need to change the value at all.&amp;nbsp; You can just display the values using a different format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input old_date mmddyy6.;
  format old_date mmddyy6.;
cards;
040623
033023
040623
;
data want;
  set have;
  new_date = old_date;
  format new_date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;OBS    old_date      new_date

 1      040623     2023-04-06
 2      033023     2023-03-30
 3      040623     2023-04-06
&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2023 23:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-to-Date-mmddyy/m-p/871756#M344426</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-24T23:20:39Z</dc:date>
    </item>
  </channel>
</rss>

