<?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: How to convert characters that are not in a proper date format into SAS date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709137#M218001</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sasdate = input(scan(chardate,1," "),mmddyy10.);
format sasdate yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 Jan 2021 09:50:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-01-03T09:50:01Z</dc:date>
    <item>
      <title>How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709133#M217997</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have character variables like these:&lt;BR /&gt;1/25/2017 4:49:01 PM&lt;/P&gt;&lt;P&gt;12/1/2017 12:07:00 PM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert the date part into SAS date. The problem is there are no "0" before months and days (for example they should be like "01/25/2017 4:49:01 PM"). Since&amp;nbsp;MDY are not in certain digits, I can't use "SASDATE = MDY(SUBSTR......" to extract the date properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it sounds simple but I can't find a solution so far. Hope there's a way to solve this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks a lot!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 08:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709133#M217997</guid>
      <dc:creator>sylvia106</dc:creator>
      <dc:date>2021-01-03T08:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709134#M217998</link>
      <description>&lt;P&gt;Solution is given in next link:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Datetime-format/m-p/375750" target="_self"&gt;https://communities.sas.com/t5/SAS-Programming/Datetime-format/m-p/375750&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 08:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709134#M217998</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-03T08:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709135#M217999</link>
      <description>&lt;P&gt;Hi please try this :I just made some nesting for fiinding the "/"&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tocorrect;
input date_to_amend $30. ;
datalines;
1/25/2017 4:49:01 PM
12/1/2017 12:07:00 PM

;
run;

data corrected ;
   set  tocorrect;
    format  sasdate DATE9.;
   format month 8.;
   format day 8.;
   format year 8.;
   month=substr(date_to_amend,1, find(date_to_amend,"/")-1);
   day=substr(substr(date_to_amend, find(date_to_amend,"/")+1,length(date_to_amend)),1, find(substr(date_to_amend, find(date_to_amend,"/")+1,length(date_to_amend)),"/")-1);
   year = substr(substr(date_to_amend,1, find(date_to_amend," ")-1),length(substr(date_to_amend,1, find(date_to_amend," ")-1))-3,4);
   sasdate=mdy(month,day,year);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 09:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709135#M217999</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2021-01-03T09:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709137#M218001</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sasdate = input(scan(chardate,1," "),mmddyy10.);
format sasdate yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 09:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709137#M218001</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-03T09:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709138#M218002</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date_to_amend $30. ;
datalines;
1/25/2017 4:49:01 PM
12/1/2017 12:07:00 PM
;
run;

data want;
set have;
New_Date=PUT(input(scan(date_to_amend,1,' '),MMDDYY10.),MMDDYY10.)||' '||strip(scan(date_to_amend,2,' ')||' '||scan(date_to_amend,3,' '));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Jan 2021 10:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709138#M218002</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2021-01-03T10:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709139#M218003</link>
      <description>Thank you so much!! It works well with just some simple lines!</description>
      <pubDate>Sun, 03 Jan 2021 10:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709139#M218003</guid>
      <dc:creator>sylvia106</dc:creator>
      <dc:date>2021-01-03T10:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709140#M218004</link>
      <description>Thank you!! This one took me some time to understand but it works! I think this method is useful for dealing with messy data &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sun, 03 Jan 2021 10:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709140#M218004</guid>
      <dc:creator>sylvia106</dc:creator>
      <dc:date>2021-01-03T10:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert characters that are not in a proper date format into SAS date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709149#M218009</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362490"&gt;@sylvia106&lt;/a&gt;&amp;nbsp; Sorry late to the party. Your pattern seems pretty straight forward and convenient to just read the &lt;STRONG&gt;datepart&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;with the appropriate informat. In your sample, the date part of the date-time character value appears to be in the form MMDDYY.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you could do is, just read upto 10 bytes of character by specifying the informat width as 10 i.e. mmddyy&lt;STRONG&gt;10. . Internally,&amp;nbsp;&lt;/STRONG&gt;SAS reads 10 bytes of char which in other words is a &lt;STRONG&gt;non-standard&lt;/STRONG&gt; date. The pre-compiled INFORMAT will look up i.e. assign the appropriate integer date value. Then, you can of course assign a format of your choice.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data tocorrect;
input date_to_amend $30. ;
datalines;
1/25/2017 4:49:01 PM
12/1/2017 12:07:00 PM
;
run;

data want;
 set tocorrect;
 sas_date=input(date_to_amend,mmddyy10.);
 format sas_date date9.;
run&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 15:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-characters-that-are-not-in-a-proper-date-format/m-p/709149#M218009</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-03T15:15:34Z</dc:date>
    </item>
  </channel>
</rss>

