<?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 character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05) in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580176#M7811</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
char_datetime='2013-03-06T12:23:20.000-05';
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Aug 2019 15:31:57 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-08-09T15:31:57Z</dc:date>
    <item>
      <title>Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580173#M7810</link>
      <description>&lt;P&gt;I am a beginner SAS University edition user so I'm not too familliar with all the terminology.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to convert a character variable into a datetime variable. My variable is called startdate_q and the format is currently YYYY-MM_DDTHH:MM: SS.000-05. One cell under the variable startdate_q reads&amp;nbsp;&lt;SPAN&gt;2013-03-06T12:23:20.000-05&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Im not sure what the last 7 characters represent (.000-05) so I would like to get rid of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please give me the exact code to convert this character variable into a datetime variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using this code but it didnt work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set old;&lt;BR /&gt;startdate_Q_new = startdate_Q;&lt;BR /&gt;format startdate_Q_new yymmdd10.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580173#M7810</guid>
      <dc:creator>andreaat</dc:creator>
      <dc:date>2019-08-09T15:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580176#M7811</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
char_datetime='2013-03-06T12:23:20.000-05';
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580176#M7811</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T15:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580177#M7812</link>
      <description>&lt;P&gt;I ran that code and it didn't work. 3 new numeric variables were created: want_date_time, k and k1 and none of them contain any data in them. No error code came back but this is what the log said&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       76:25   
 NOTE: Variable k is uninitialized.
 NOTE: Variable k1 is uninitialized.
 NOTE: There were 30128 observations read from the data set WORK.CLSA2.
 NOTE: The data set WORK.CLSA3 has 30128 observations and 2363 variables.
 NOTE: DATA statement used (Total process time):
       real time           10.68 seconds
       cpu time            4.94 seconds
      &lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580177#M7812</guid>
      <dc:creator>andreaat</dc:creator>
      <dc:date>2019-08-09T15:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580181#M7813</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254087"&gt;@andreaat&lt;/a&gt;&amp;nbsp; I owe you an apology for the EDIT that I did and didn't notify you. Please accept my sincere apologies. The edited version latest is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
char_datetime='2013-03-06T12:23:20.000-05';
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am really sorry again!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580181#M7813</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T15:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580186#M7814</link>
      <description>&lt;P&gt;No worries Thank you for helping me with this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use that code, only one row of data is made with the old variable chart_datetime and the new variable want_datetime.&lt;/P&gt;&lt;P&gt;I added in a set statement to your code and now&amp;nbsp;all of the new want_datetime data points have the date and time of &lt;SPAN&gt;06MAR2013:12:23:20.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is how my code looked&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
char_datetime='2013-03-06T12:23:20.000-05';
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Each row of data has a different time and the new variable (want_date_time) produces the same date for all datapoints. Any suggestions on what I should do to make sure that each row of data is produced with its corresponding date and time?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 15:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580186#M7814</guid>
      <dc:creator>andreaat</dc:creator>
      <dc:date>2019-08-09T15:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580188#M7815</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/254087"&gt;@andreaat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;No worries Thank you for helping me with this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use that code, only one row of data is made with the old variable chart_datetime and the new variable want_datetime.&lt;/P&gt;
&lt;P&gt;I added in a set statement to your code and now&amp;nbsp;all of the new want_datetime data points have the date and time of &lt;SPAN&gt;06MAR2013:12:23:20.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is how my code looked&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
char_datetime='2013-03-06T12:23:20.000-05';
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Each row of data has a different time and the new variable (want_date_time) produces the same date for all datapoints. Any suggestions on what I should do to make sure that each row of data is produced with its corresponding date and time?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you read the code you ran?&amp;nbsp; You are saying, in order. 1) Create a new dataset named WANT. 2) read in the data from an existing dataset named HAVE. 3) Set CHAR_DATETIME to a constant text value, so it will have the same value for every observation read from HAVE. It the variable existed in HAVE the original value from HAVE will be overwritten, and if it didn't exist then a new variable will be created. 4) Convert this constant in CHAR_DATETIME into numeric datetime value in WANT_DATE_TIME by using the INPUT() function.&amp;nbsp; 5) attach the DATETIME format to WANT_DATE_TIME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably want to change the dataset names in the DATA and SET statement. Remove the first assignment statement.&amp;nbsp; And change the variables names in the remaining assignment statement and the format statement to match the names of the variable you actually have the variable you want to create.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 16:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580188#M7815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-09T16:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to datetime variable (current format is YYYY-MM-DDTHH:MM:SS.000-05)</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580198#M7816</link>
      <description>&lt;P&gt;Sir Tom &amp;nbsp; has explained at length that is exquisite akin to that of a text book tutorial.&amp;nbsp; I hope you understood those points.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you did understand, you would have hopefully corrected your code to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
want_date_time=input(char_datetime, B8601DT.);
format want_date_time datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 16:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Convert-character-variable-to-datetime-variable-current-format/m-p/580198#M7816</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T16:33:22Z</dc:date>
    </item>
  </channel>
</rss>

