<?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 - &amp;gt; Convert Variable from Character to Datetime. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239973#M44228</link>
    <description>&lt;P&gt;Well, I don't recognise that date time format. &amp;nbsp;You get a 0 because the date and time given is the start point from where SAS calculates date values. &amp;nbsp;Remember under the hood, SAS stores dates as number of days since 01JAN1960, and datetimes and number of seconds since 01JAN1960 00:00, so unformated that date is 0, 01jan would be 1 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the other part, I would recommen changing whatever that format of date time is over to ISO standard datetime:&lt;/P&gt;
&lt;P&gt;yyyy-mm-ddThh:mm:ss.ss&lt;/P&gt;</description>
    <pubDate>Fri, 18 Dec 2015 12:08:45 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-12-18T12:08:45Z</dc:date>
    <item>
      <title>How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239968#M44226</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to convert variable from character to DATETIME. format. When I use the following code the latest six digits were 0 while they should be&amp;nbsp;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;860184"&lt;/SPAN&gt;&amp;nbsp;.&amp;nbsp;What should I do to see right result. Also I would like to ask you when I try to overwrite "Date" variable I got the value as "0" or missing so I assigned the value in new variable then I dropped the variable and changed the new &amp;nbsp;ariable name as old variable name. Is it possible to overwrite the variable without assign the variables value to new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE(Drop=Date Rename=(Date2=Date));
Date="1960-01-01-00.00.00.860184";
/*Date=input(Date,anydtdtm.);*/
Date2=input(Date,anydtdtm.);
FORMAT Date2 datetime27.6;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1234i45CCC33041340D20/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Mistake.png" title="Mistake.png" /&gt;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 11:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239968#M44226</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-18T11:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239973#M44228</link>
      <description>&lt;P&gt;Well, I don't recognise that date time format. &amp;nbsp;You get a 0 because the date and time given is the start point from where SAS calculates date values. &amp;nbsp;Remember under the hood, SAS stores dates as number of days since 01JAN1960, and datetimes and number of seconds since 01JAN1960 00:00, so unformated that date is 0, 01jan would be 1 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the other part, I would recommen changing whatever that format of date time is over to ISO standard datetime:&lt;/P&gt;
&lt;P&gt;yyyy-mm-ddThh:mm:ss.ss&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 12:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239973#M44228</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-18T12:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239975#M44229</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, when I try to convert to numeric variable it brings 0 I think it is related the date(1960) which I wrote in "Date" variable. But when I overwrite the variable as Datetime. format it brings missing value. What is the reason for that ??? Also, I couldn't understand why last 6 digits were zero even I've already put &amp;nbsp;the value "&lt;SPAN&gt;860184" &amp;nbsp;in the&lt;/SPAN&gt;&amp;nbsp;"Date" variable when I assign the value in new variable as Datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 12:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239975#M44229</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-18T12:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239994#M44234</link>
      <description>&lt;P&gt;Well, the date conversion is pretty straightforward. &amp;nbsp;You assign date to be a character:&lt;/P&gt;
&lt;P&gt;Date="1960-01-01T00:00:00.860184";&lt;/P&gt;
&lt;P&gt;Then you try to put a number - that date is 0 numerically - into the character variable (i.e. implicit conversion).&lt;BR /&gt;Date=input(Date,anydtdtm.);&lt;/P&gt;
&lt;P&gt;So date becomes the numeric value of the date you gave, which is "0". &amp;nbsp;02 Jan would be "1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 13:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/239994#M44234</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-18T13:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240005#M44238</link>
      <description>&lt;P&gt;Okay, lets think about value of "Date" is -&amp;gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;Date&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"2000-12-12-00.00.00.860184"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I take many datas from Excel or another environment as Datetime27.6 format. I mean the data which is located at Excel equal to&amp;nbsp;&lt;SPAN&gt;Datetime27.6 format in SAS.&lt;/SPAN&gt;&amp;nbsp;When I Import these datas they come as Character type and I try to change the datas from Character to Datetime27.6 format but when I try it, it becomes as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;Date&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"2000-12-12-00.00.00.000000"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but actual datas' last 6 digit include&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;.860184&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so why I can't see the actual values and how can I fix it, how I can see whole of the actual value ???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 13:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240005#M44238</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-12-18T13:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240022#M44240</link>
      <description>&lt;P&gt;You aren't importing the data correctly. I'm not sure what format you'll need to get your data in, a variant on E8601DT I imagine, or may need to format your date to match a present format....or create your own informat.&amp;nbsp;&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;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
length date_char $30.;
date_char="2000-12-12T00:00:00.860184";
date_num_raw=input(date_char, e8601dt26.6);
date_num_fmt=date_num_raw;

format date_num_fmt datetime27.6 date_num_raw 26.6;
run;&lt;BR /&gt;&lt;BR /&gt;proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; Obs            date_char             date_num_raw                                 date_num_fmt

  1     2000-12-12T00:00:00.860184    2000-12-12T00:00:00.860184      12DEC2000:00:00:00.860184
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 15:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240022#M44240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-18T15:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: How To - &gt; Convert Variable from Character to Datetime.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240098#M44266</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's Note: Since the character date does not conform to a given SAS date informat, the code provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;is the best solution.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the B8601DJ20.6 informat after removing the punctuation marks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=date rename=(date2=date));
date="2000-12-12-00.00.00.860184";
date2=input(compress(date, '-.'), b8601dj20.6);
format date2 datetime27.6;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of listing the punctuation marks explicitly in the second argument of the COMPRESS function, you can use the 'p' modifier to remove &lt;EM&gt;any&lt;/EM&gt; punctuation marks (as well as blanks):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date2=input(compress(date,,'p'), b8601dj20.6);&lt;/CODE&gt;&lt;/PRE&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, 31 Aug 2017 18:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-gt-Convert-Variable-from-Character-to-Datetime/m-p/240098#M44266</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2017-08-31T18:37:08Z</dc:date>
    </item>
  </channel>
</rss>

