<?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: char date to numeric conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325217#M72313</link>
    <description>&lt;P&gt;Post example test data in the form of a datastep whenever you post a question. &amp;nbsp;This helps us see the data as you have it. &amp;nbsp;Otherwise we are guessing. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  svstd="2009-02-17";
  svsstd_num=input(svstd,yymmdd10.);
  format svsstd_num date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Note that you can't put a numeric value back into the character variable (i.e. svstd is character, this will just return a character result.). &amp;nbsp;Put the result of the conversion into a numeric variable.&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2017 09:55:56 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-17T09:55:56Z</dc:date>
    <item>
      <title>char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325212#M72309</link>
      <description>&lt;P&gt;i have a date variable which is in numeric and in "2009-02-17" format. i am calculating flag variable with char date in "&lt;SPAN&gt;2009-02-15&lt;/SPAN&gt;" and converting it to numeric like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ae053;&lt;BR /&gt; set ae052;&lt;BR /&gt; format SVSTD&amp;nbsp;date9.;&lt;BR /&gt; SVSTD = input ( SVSTD, MMDDYY10.);&lt;BR /&gt; if ASTD &amp;lt; SVSTD then flag= "N";&lt;BR /&gt; else flag= "Y";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still get error in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can anyone help me in this&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 09:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325212#M72309</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-01-17T09:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325213#M72310</link>
      <description>&lt;P&gt;If svstd is already a SAS date variable (numeric, date format), then you can't use it as argument to the input() function, as that expects a character value.&lt;/P&gt;
&lt;P&gt;Please supply your example data in a data step for testing, and your expected result.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 09:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325213#M72310</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-17T09:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325216#M72312</link>
      <description>&lt;TABLE width="274"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;pt&lt;/TD&gt;
&lt;TD width="73"&gt;svdt&lt;/TD&gt;
&lt;TD width="73"&gt;ASTDT&lt;/TD&gt;
&lt;TD width="64"&gt;flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;101&lt;/TD&gt;
&lt;TD&gt;2009-02-17&lt;/TD&gt;
&lt;TD&gt;2009-02-09&lt;/TD&gt;
&lt;TD&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;102&lt;/TD&gt;
&lt;TD&gt;2009-08-03&lt;/TD&gt;
&lt;TD&gt;2009-08-02&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;103&lt;/TD&gt;
&lt;TD&gt;2009-02-09&lt;/TD&gt;
&lt;TD&gt;2009-02-10&lt;/TD&gt;
&lt;TD&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case SVDT is in char and format and length as 10.&lt;/P&gt;
&lt;P&gt;ASDT is numeric and&amp;nbsp;&lt;SPAN&gt;format and length as 10.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 09:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325216#M72312</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-01-17T09:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325217#M72313</link>
      <description>&lt;P&gt;Post example test data in the form of a datastep whenever you post a question. &amp;nbsp;This helps us see the data as you have it. &amp;nbsp;Otherwise we are guessing. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  svstd="2009-02-17";
  svsstd_num=input(svstd,yymmdd10.);
  format svsstd_num date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Note that you can't put a numeric value back into the character variable (i.e. svstd is character, this will just return a character result.). &amp;nbsp;Put the result of the conversion into a numeric variable.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 09:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325217#M72313</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-17T09:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325218#M72314</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've got the informat wrong&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be&amp;nbsp;YYMMDD10., not MMDD10.&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>Tue, 17 Jan 2017 10:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325218#M72314</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-17T10:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325219#M72315</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/62004"&gt;@vraj1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;TABLE width="274"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;pt&lt;/TD&gt;
&lt;TD width="73"&gt;svdt&lt;/TD&gt;
&lt;TD width="73"&gt;ASTDT&lt;/TD&gt;
&lt;TD width="64"&gt;flag&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;101&lt;/TD&gt;
&lt;TD&gt;2009-02-17&lt;/TD&gt;
&lt;TD&gt;2009-02-09&lt;/TD&gt;
&lt;TD&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;102&lt;/TD&gt;
&lt;TD&gt;2009-08-03&lt;/TD&gt;
&lt;TD&gt;2009-08-02&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;103&lt;/TD&gt;
&lt;TD&gt;2009-02-09&lt;/TD&gt;
&lt;TD&gt;2009-02-10&lt;/TD&gt;
&lt;TD&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case SVDT is in char and format and length as 10.&lt;/P&gt;
&lt;P&gt;ASDT is numeric and&amp;nbsp;&lt;SPAN&gt;format and length as 10.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot change the type of a variable, you have to create a new one and remove the old:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input pt svdt :$10. astdt :yymmdd10. flag :$1.;
format astdt yymmddd10.;
cards;
101 2009-02-17 2009-02-09 N
102 2009-08-03 2009-08-02 Y
103 2009-02-09 2009-02-10 N
;
run;

data want;
set have (rename=(svdt=svdt_old));
format svdt yymmddd10.;
svdt = input(svdt_old,yymmdd10.);
drop svdt_old;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result looks like this:&lt;/P&gt;
&lt;PRE&gt;Obs     pt         astdt    flag          svdt

 1     101    2009-02-09     N      2009-02-17
 2     102    2009-08-02     Y      2009-08-03
 3     103    2009-02-10     N      2009-02-09
&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jan 2017 10:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325219#M72315</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-17T10:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325220#M72316</link>
      <description>&lt;P&gt;And, for the future:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"I still get error in the log."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is NOT helpful. Post at least the ERROR message text, but much better is to post the log including the whole step where the ERROR happened.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 10:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325220#M72316</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-01-17T10:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: char date to numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325222#M72318</link>
      <description>&lt;P&gt;sorry for that, will make sure abouit it&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 10:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/char-date-to-numeric-conversion/m-p/325222#M72318</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2017-01-17T10:07:00Z</dc:date>
    </item>
  </channel>
</rss>

