<?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 do I convert a date stored as string into a SAS datetime with proc sql? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/327208#M62376</link>
    <description>&lt;P&gt;Thank you, the reason I want to convert to datetime is because I'm learning how to handle both SAS date and datetime formats &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jan 2017 22:10:13 GMT</pubDate>
    <dc:creator>Datino</dc:creator>
    <dc:date>2017-01-24T22:10:13Z</dc:date>
    <item>
      <title>How do I convert a date stored as string into a SAS datetime with proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326861#M62355</link>
      <description>&lt;P&gt;If I have a value like YYYYMMDD stored as string (for example 20170123), how can I convert it to SAS datettime?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 21:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326861#M62355</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2017-01-23T21:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I convert a date stored as string into a SAS datetime with proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326870#M62361</link>
      <description>&lt;P&gt;If it's a string,&amp;nbsp; you will need to assign the date value to a new variable since SAS stores dates as numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = input(stringvar, yymmdd8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you actually have separators in your string, such as yyyy/mm/dd you will need to expand the width:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = input(stringvar, yymmdd10.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives you a SAS date (not a datetime).&amp;nbsp; While you can convert this to a datetime value, it's not clear why you would want to do that.&amp;nbsp; You don't actually have any measurement of hours, minutes, or seconds in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 22:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326870#M62361</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-23T22:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I convert a date stored as string into a SAS datetime with proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326879#M62364</link>
      <description>&lt;P&gt;Don't forget to assign a format to the variable so you can see the date value instead of the internal numeric stored value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a date and time parts the function DHMS will create a datetime variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DT = dhms(date, hours, minutes, seconds);&lt;/P&gt;
&lt;P&gt;If you don't have any time values you can set a default such as&lt;/P&gt;
&lt;P&gt;DT = dhms(date,0,0,0); which would be midnight at the start of the day.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 22:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/326879#M62364</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-23T22:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I convert a date stored as string into a SAS datetime with proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/327208#M62376</link>
      <description>&lt;P&gt;Thank you, the reason I want to convert to datetime is because I'm learning how to handle both SAS date and datetime formats &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 22:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/327208#M62376</guid>
      <dc:creator>Datino</dc:creator>
      <dc:date>2017-01-24T22:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I convert a date stored as string into a SAS datetime with proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/327282#M62387</link>
      <description>&lt;P&gt;Also usually...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Date values are stored as the number of days since 1960/01/01&lt;/P&gt;
&lt;P&gt;SAS Time values are stored as the number of &amp;nbsp;seconds since midnight&lt;/P&gt;
&lt;P&gt;SAS Datetime values are stored as the number of seconds since 1960/01/01&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Knowing that, you can easily switch between Date, Datetime and time values just by doing some maths:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATETIME = DATE*(24*60*60)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATE = int(DATETIME/(24*60*60))&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIME = mod(DATETIME,24*60*60)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you&amp;nbsp;could use the dedicated functions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Datepart, that will&amp;nbsp;return the Date value of it's Datetime value argument&lt;/P&gt;
&lt;P&gt;Timepart, that will return the Time vale of it's Datetime value argument&lt;/P&gt;
&lt;P&gt;DHMS, that will return the Datetime value of it's Date value argument (+ the hour, minute and second specified)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More on Date, Datime and Time values here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 08:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-convert-a-date-stored-as-string-into-a-SAS-datetime/m-p/327282#M62387</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-25T08:29:42Z</dc:date>
    </item>
  </channel>
</rss>

