<?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 time to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793338#M254261</link>
    <description>&lt;PRE&gt;data test;
  input string $20.;
  _string=prxchange('s/(\d?\d)(\d\d)(\d\d)/\1:\2:\3/',1,string);
  time=input(_string,anydttme32.);
  format time tod8. string $quote.;
cards;
122300 PM
91300 AM
91300 pm
82500 AM
82500 AM
;&lt;/PRE&gt;</description>
    <pubDate>Sun, 30 Jan 2022 08:50:11 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-01-30T08:50:11Z</dc:date>
    <item>
      <title>Convert character time to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793292#M254239</link>
      <description>&lt;P&gt;Using SAS 9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I convert a character time variable&amp;nbsp;to a SAS time variable? Examples of my time variable are below. The time could be 5 or 6 digits before the am/pm in my data. Thank you&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"122300 PM"&lt;/P&gt;
&lt;P&gt;"91300 AM"&lt;/P&gt;
&lt;P&gt;"82500 AM"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 17:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793292#M254239</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2022-01-29T17:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character time to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793297#M254242</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do the numbers represent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are only 24*60*60=86400 seconds in a day?&lt;/P&gt;
&lt;P&gt;Hence, the below is probably NOT what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
LENGTH A $ 10 b 8;
a="122300 PM"; b=input(scan(a,1),6.); put b= time8.;
a="91300 AM";  b=input(scan(a,1),6.); put b= time8.;
a="82500 AM";  b=input(scan(a,1),6.); put b= time8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 29 Jan 2022 17:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793297#M254242</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-01-29T17:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character time to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793298#M254243</link>
      <description>&lt;P&gt;I think you will have to read the first part using HHMMSS informat than then manually add 12 hours when appropriate.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input string $char10.;
  time=input(string,hhmmss6.);
  if time &amp;lt; '12:00't and find(string,'PM','i') then time+'12:00't;
  format time tod8. string $quote.;
  put time string ;
cards;
122300 PM
91300 AM
91300 pm
82500 AM
 82500 AM
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;12:23:00 "122300 PM"
09:13:00 "91300 AM"
21:13:00 "91300 pm"
08:25:00 "82500 AM"
08:25:00 " 82500 AM"
&lt;/PRE&gt;
&lt;P&gt;If you want a expression you use that avoids the IF/THEN try this one.&amp;nbsp; It will read in the [h]hmmss string part and then put it using TOD format and append the AM/PM suffix and then read the whole result using the TIME informat that recognizes the AM/PM.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  time=input(put(input(string,hhmmss6.),tod8.)||scan(string,2,' '),time12.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Jan 2022 18:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793298#M254243</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-29T18:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character time to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793338#M254261</link>
      <description>&lt;PRE&gt;data test;
  input string $20.;
  _string=prxchange('s/(\d?\d)(\d\d)(\d\d)/\1:\2:\3/',1,string);
  time=input(_string,anydttme32.);
  format time tod8. string $quote.;
cards;
122300 PM
91300 AM
91300 pm
82500 AM
82500 AM
;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Jan 2022 08:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-time-to-numeric/m-p/793338#M254261</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-30T08:50:11Z</dc:date>
    </item>
  </channel>
</rss>

