<?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: Different formats of character dates into numeric conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817984#M322865</link>
    <description>&lt;P&gt;If those two patterns are all you have then just check which one you have and use the right code to each.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $19.;
datalines;
21329
22614
22636
2022-02-21
2022-03-15
2022-04-29
;

data want;
  set have;
  if index(string,'-') then date=input(string,yymmdd10.);
  else date=input(string,32.);
  format date yymmdd10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1655175270668.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72260iB286FC99A0EFD9E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1655175270668.png" alt="Tom_0-1655175270668.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jun 2022 02:54:40 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-14T02:54:40Z</dc:date>
    <item>
      <title>Different formats of character dates into numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817978#M322862</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have different formats of values in character date variable. I am unable to convert it to numeric. Can anyone help me with the solution. I tried anydtdt and other formats too. But no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
input date $19.;
datalines;
21329
22614
22636
2022-02-21
2022-03-15
2022-04-29
;
run;

data want;
set have;
want=input(date,yymmdd10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ad&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 02:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817978#M322862</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2022-06-14T02:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Different formats of character dates into numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817984#M322865</link>
      <description>&lt;P&gt;If those two patterns are all you have then just check which one you have and use the right code to each.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $19.;
datalines;
21329
22614
22636
2022-02-21
2022-03-15
2022-04-29
;

data want;
  set have;
  if index(string,'-') then date=input(string,yymmdd10.);
  else date=input(string,32.);
  format date yymmdd10.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1655175270668.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72260iB286FC99A0EFD9E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1655175270668.png" alt="Tom_0-1655175270668.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 02:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817984#M322865</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-14T02:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Different formats of character dates into numeric conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817985#M322866</link>
      <description>&lt;P&gt;What dates are supposed to be represented by the first 3 values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can conditionally execute the input function.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if length (date)=10 then want=input(date,yymmdd10.);
   if length (date)=5 then want = input(date,f5.);
   format want date9.;
run;&lt;/PRE&gt;
&lt;P&gt;So this code only attempts to use the yymmdd10 format with the string value is 10 characters.&lt;/P&gt;
&lt;P&gt;The second bit is guessing that someone may have done something very odd and managed to convert the SAS date numeric values to character somewhere and this reads them back to a numeric value and is then formatted. If that is not the case you really have to tell us what date is represented by 21329 as it may require some careful parsing.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 03:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-formats-of-character-dates-into-numeric-conversion/m-p/817985#M322866</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-14T03:00:03Z</dc:date>
    </item>
  </channel>
</rss>

