<?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 Date to Numeric (I know this has been asked before) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538888#M148397</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thank you for your response. If you look at the link that I posted, the solution achieved in that discussion also goes through a similar set of steps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your source variable is CHARACTER then you need to make a NEW variable if want to store it as an actual date value.&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  first_chemo_date_num&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmdd8&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; first_chemo_date_num yymmddn8&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  yr&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;year&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date_num&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  mth&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date_num&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I understand that I am starting of with a character, however I thought the input function was supposed to cast it into a numeric date as explained in this example and that is what I tried. Just to be clear, besides the example code I posted, I also tried creating a new variable exactly as shown .&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 04:54:26 GMT</pubDate>
    <dc:creator>UdayGuntupalli</dc:creator>
    <dc:date>2019-02-27T04:54:26Z</dc:date>
    <item>
      <title>Convert Character Date to Numeric (I know this has been asked before)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538879#M148390</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;I know there are many posts on the community and I tried following the suggestions in these posts without much success. Here is a very relevant post (&lt;A href="https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/td-p/288783" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/URGENT-extract-Year-and-Month-from-a-date-variable/td-p/288783&lt;/A&gt;) .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Let me show what I have tried to do and my code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data Have; 
	Set Work.temp (Keep = UtcReadTime ); 
	Left = scan(UtcReadTime,1,'T');
  	Right = scan(UtcReadTime,2,'T');
  	format Left yymmdd8.; 
  	format Right yymmdd8.; 
  	Date = input(Left,yymmdd8.);
  	Year = Year(Date); 
  	Month = Month(Date); 
  	Day = Day(Date); 
  	Hour = Hour(Right);
Run; &lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27519iEAC300782F0AD118/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538879#M148390</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2019-02-27T04:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character Date to Numeric (I know this has been asked before)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538883#M148392</link>
      <description>&lt;P&gt;This seems to work, but I am curious as to why my previous approach does not work :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data Have; 
	Set Work.sitepvforecast (Keep = UtcReadTime ); 
	Left = scan(UtcReadTime,1,'T');
  	Right = scan(UtcReadTime,2,'T');
  	Year = substr(Left,1,4);
  	Year_n = input(Year, best12.);
  	Month = substr(Left,6,2); 
  	Month_n = input(Month,best12.); 
  	Day = substr(Left,9,2);
  	Day_n = input(Day,best12.);
  	Hour = substr(Right,1,2);
  	Hour_n = input(Hour,best12.); 
Run; &lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538883#M148392</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2019-02-27T04:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character Date to Numeric (I know this has been asked before)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538886#M148395</link>
      <description>&lt;P&gt;SAS functions YEAR, MONTH, DAY, etc. work on SAS dates which are numbers. You were applying them to character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;204  data _null_;
205  t = today();
206  y = year(t);
207  m = month(t);
208  d = day(t);
209  str = put(t, yymmdd10.);
210  put (_all_) (=);
211  run;

t=21606 y=2019 m=2 d=26 str=2019-02-26
&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538886#M148395</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-27T04:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character Date to Numeric (I know this has been asked before)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538888#M148397</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thank you for your response. If you look at the link that I posted, the solution achieved in that discussion also goes through a similar set of steps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your source variable is CHARACTER then you need to make a NEW variable if want to store it as an actual date value.&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  first_chemo_date_num&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmdd8&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; first_chemo_date_num yymmddn8&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  yr&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;year&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date_num&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  mth&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;first_chemo_date_num&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I understand that I am starting of with a character, however I thought the input function was supposed to cast it into a numeric date as explained in this example and that is what I tried. Just to be clear, besides the example code I posted, I also tried creating a new variable exactly as shown .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 04:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538888#M148397</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2019-02-27T04:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character Date to Numeric (I know this has been asked before)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538889#M148398</link>
      <description>&lt;P&gt;The only problem with your code was the width of the informat. By asking yymmdd8. you were missing the last two characters of the date part of the string. Look:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;218  data _null_;
219  str = "2019-02-27T04:00:00";
220  date = input(str, yymmdd10.);
221  format date yymmddn8.;
222  put (_all_) (=);
223  run;

str=2019-02-27T04:00:00 date=20190227
&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 05:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Character-Date-to-Numeric-I-know-this-has-been-asked/m-p/538889#M148398</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-27T05:28:12Z</dc:date>
    </item>
  </channel>
</rss>

