<?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 Numeric type to Date type? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604194#M175136</link>
    <description>&lt;P&gt;Likely all you need to do is apply the format.&lt;/P&gt;
&lt;PRE&gt;data times;
   if date1 = . then final_date = date2;
   else final_date = date1;
   format final_date datetime20.;
run;&lt;/PRE&gt;
&lt;P&gt;NOTE: The PUT function &lt;STRONG&gt;always&lt;/STRONG&gt; creates character output. That the purpose of the Put function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All SAS Date, Datetime and Time values are numeric. Dates are number of days since 1 Jan 1960, Datetimes are number of seconds since 1 Jan 1960 and Time values are number of seconds from midnight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2019 17:16:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-11-14T17:16:22Z</dc:date>
    <item>
      <title>How do I Convert Numeric type to Date type?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604188#M175131</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to convert a numeric type to a date type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My original dataset has a date type variable, I set another variable equal to this and it returns a numeric type. I want this new variable as a date type like the original. I've tried solutions from other posts but the result of those returns the date in the format I want, but as a character type. Can anyone help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I'm currently running which returns the date as character, not a date type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date1 and date2 are date types of the format ddmmmyyy:hh:mm:ss (e.g. 14NOV2019:17:01:01)&lt;/P&gt;&lt;P&gt;x_time is returned as a numeric (e.g. 0123456789)&lt;/P&gt;&lt;P&gt;final_date is a character type (e.g. "14NOV2019:17:01:01")&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data times;
if date1 = . then x_time = date2;
else x_time = date1;
final_date = put(x_time,datetime20.);
format final_date datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this explains the problem, thanks in advance for your help and feedback!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 17:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604188#M175131</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2019-11-14T17:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Convert Numeric type to Date type?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604192#M175134</link>
      <description>&lt;P&gt;Maybe&amp;nbsp;this will help &lt;A href="https://blogs.sas.com/content/sgf/2015/05/01/converting-variable-types-do-i-use-put-or-input/" target="_self"&gt;explain the difference between PUT() and INPUT()&lt;/A&gt; but you are converting it from NUMERIC to CHAR by using the PUT() statement.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 17:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604192#M175134</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-14T17:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Convert Numeric type to Date type?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604194#M175136</link>
      <description>&lt;P&gt;Likely all you need to do is apply the format.&lt;/P&gt;
&lt;PRE&gt;data times;
   if date1 = . then final_date = date2;
   else final_date = date1;
   format final_date datetime20.;
run;&lt;/PRE&gt;
&lt;P&gt;NOTE: The PUT function &lt;STRONG&gt;always&lt;/STRONG&gt; creates character output. That the purpose of the Put function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All SAS Date, Datetime and Time values are numeric. Dates are number of days since 1 Jan 1960, Datetimes are number of seconds since 1 Jan 1960 and Time values are number of seconds from midnight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 17:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604194#M175136</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-14T17:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Convert Numeric type to Date type?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604202#M175142</link>
      <description>&lt;P&gt;SAS date (and datetime and time) variables are numeric, and have certain formats attached to them to display times and dates in human-readable form. Internally, they store counts of days or counts of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you store a formatted string into a character variable with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;final_date = put(x_time,datetime20.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format final_date datetime20.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not necessary and will cause an ERROR, as you can't attach a numeric format to a character variable.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 17:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604202#M175142</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-14T17:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I Convert Numeric type to Date type?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604245#M175151</link>
      <description>&lt;P&gt;SAS only has two data types. Fixed length character strings and floating point numbers.&amp;nbsp; Note that a SAS format is just instructions for how to convert the values to text when displaying them and does not define a new type of variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If sounds like you have a numeric variable that has a format attached to it.&amp;nbsp; When you make the new variable just the values are copied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You just need to attach a format to the new variable so that it will look to you like a date.&amp;nbsp; Use the same format that was attached to the original variable if you want the values to display in the same way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data times;
  x_time = coalesce(date1,date2);
  format x_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;You might want to change your variable names.&amp;nbsp;&lt;/STRONG&gt; From the format you have attached it appears that all three of those variables contain numbers that represent DATETIME values.&amp;nbsp; Yet your names imply that two of them have DATE values and the third as a TIME value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 18:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-Convert-Numeric-type-to-Date-type/m-p/604245#M175151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-14T18:46:17Z</dc:date>
    </item>
  </channel>
</rss>

