<?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 char to Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709965#M218456</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data have;&lt;BR /&gt;date1='44204.70833333334';&lt;BR /&gt;date2=input(date1,mmddyy10.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I recreated this for demonstration purposes. I have a file that I import. The date&lt;BR /&gt;imports as a character(date1). I need to convert it to a mmddyy10. style date.&lt;BR /&gt;I attempted to do that in date2 however I get a blank value. Is there a way to convert this&lt;BR /&gt;character field to a date field&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I will bet a large stack of $$$ that value at some time was an Excel DATE and Time value.&lt;/P&gt;
&lt;P&gt;There is no way that any of the SAS MMDDYY, YYMMDD, DDMMYY or similar INFORMATS could read that value. Where is the Month, Day or Year in "44204".&lt;/P&gt;
&lt;P&gt;Create a numeric value:&lt;/P&gt;
&lt;P&gt;numval = floor (input(date1,5.) );&lt;/P&gt;
&lt;P&gt;The floor function is to remove the time portion, the decimals.&lt;/P&gt;
&lt;P&gt;Then search the forum for any of the plethora of Excel to SAS date conversions.&lt;/P&gt;
&lt;P&gt;If you actually want to convert this to a date time value then extract the decimals as a number and multiple by 24*60*60 to convert the fraction of a day the decimals represent into seconds. Then use the DHMS function with the date and seconds to create a datetime SAS value: DT = dhms(date,0,0,seconds);&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jan 2021 17:28:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-01-07T17:28:50Z</dc:date>
    <item>
      <title>Convert char to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709962#M218453</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;date1='44204.70833333334';&lt;BR /&gt;date2=input(date1,mmddyy10.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I recreated this for demonstration purposes. I have a file that I import. The date&lt;BR /&gt;imports as a character(date1). I need to convert it to a mmddyy10. style date.&lt;BR /&gt;I attempted to do that in date2 however I get a blank value. Is there a way to convert this&lt;BR /&gt;character field to a date field&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 17:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709962#M218453</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-01-07T17:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709965#M218456</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data have;&lt;BR /&gt;date1='44204.70833333334';&lt;BR /&gt;date2=input(date1,mmddyy10.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;I recreated this for demonstration purposes. I have a file that I import. The date&lt;BR /&gt;imports as a character(date1). I need to convert it to a mmddyy10. style date.&lt;BR /&gt;I attempted to do that in date2 however I get a blank value. Is there a way to convert this&lt;BR /&gt;character field to a date field&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I will bet a large stack of $$$ that value at some time was an Excel DATE and Time value.&lt;/P&gt;
&lt;P&gt;There is no way that any of the SAS MMDDYY, YYMMDD, DDMMYY or similar INFORMATS could read that value. Where is the Month, Day or Year in "44204".&lt;/P&gt;
&lt;P&gt;Create a numeric value:&lt;/P&gt;
&lt;P&gt;numval = floor (input(date1,5.) );&lt;/P&gt;
&lt;P&gt;The floor function is to remove the time portion, the decimals.&lt;/P&gt;
&lt;P&gt;Then search the forum for any of the plethora of Excel to SAS date conversions.&lt;/P&gt;
&lt;P&gt;If you actually want to convert this to a date time value then extract the decimals as a number and multiple by 24*60*60 to convert the fraction of a day the decimals represent into seconds. Then use the DHMS function with the date and seconds to create a datetime SAS value: DT = dhms(date,0,0,seconds);&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 17:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709965#M218456</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-07T17:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert char to Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709968#M218457</link>
      <description>&lt;P&gt;Looks to me like you have imported an Excel spreadsheet where one of the column had some datetime values and some character strings. So SAS had to create the variable as character. When it does that the datetime values are stored as strings that represent the number Excel uses to store the value.&amp;nbsp; First convert the value to a number using INPUT() then adjust to value by the difference in basis dates used for counting days.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date2=input(date1,32.)+'30DEC1899'd ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need the time component you will need to convert the value from days to seconds.&amp;nbsp; In Excel the 0.70833333334 means what percent of 24 hours.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date3=dhms(date2,0,0,0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then attach the display format you want to use for these two new variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format date2 date9. date3 datetime19. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;214   data have;
215     date1='44204.70833333334';
216     date2=input(date1,32.)+'30DEC1899'd ;
217     date3=dhms(date2,0,0,0);
218     format date2 date9. date3 datetime19. ;
219     put (_all_) (=/);
220     put (date2 date3) (= comma20. /);
221   run;


date1=44204.70833333334
date2=08JAN2021
date3=08JAN2021:17:00:00

date2=22,289
date3=1,925,744,400
&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2021 17:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-char-to-Date/m-p/709968#M218457</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-07T17:39:32Z</dc:date>
    </item>
  </channel>
</rss>

