<?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 time is8601. format to MM:SS format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908962#M358613</link>
    <description>&lt;P&gt;If you are only using a subset of ISO8601 then you should be able to use simpler methods to parse the strings.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should increase your examples to cover all of the possible types of values to make sure your algorithm can handle the values you get.&amp;nbsp; For example do you ever have minutes and seconds?&amp;nbsp; Seconds only?&amp;nbsp; Do you always have PT as the first two characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Dec 2023 06:19:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-20T06:19:10Z</dc:date>
    <item>
      <title>Convert time is8601. format to MM:SS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908951#M358606</link>
      <description>&lt;P&gt;Thank you for the help and your time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following time format in is8601 format(PT14M), which I want to convert into MM: SS (14:00) character format. if its&amp;nbsp;PT2M then it should display as "02:00"&lt;/P&gt;
&lt;P&gt;data x;&lt;BR /&gt;is8601 = 'PT14M';&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;is8601 = 'PT2M';&lt;/P&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/* mmss_char = "14:00";*/&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 01:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908951#M358606</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-12-20T01:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time is8601. format to MM:SS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908958#M358610</link>
      <description>&lt;P&gt;So you want to assume that the unknown number of seconds is zero?&lt;/P&gt;
&lt;P&gt;Similarly for hours?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Playing around it looks like the $N8601B informat can convert those variable strings into fixed position strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input duration $20.;
  normal = input(duration,$N8601B50.);
cards;
PT14M
PT2M
P0DT14M
2023-01-02T01:02:03
2023-11-22T01:02:03
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    duration                    normal

 1     PT14M                  FFFFFFFFF14FFFFC
 2     PT2M                   FFFFFFFFF02FFFFC
 3     P0DT14M                FFFFF00FF14FFFFC
 4     2023-01-02T01:02:03    2023102010203FFD
 5     2023-11-22T01:02:03    2023B22010203FFD
&lt;/PRE&gt;
&lt;P&gt;So the Minutes are in positions 10 and 11 and seconds in 12 and 13.&amp;nbsp; The unknown fields are coded as FF.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input duration $20.;
  normal = input(duration,$N8601B16.);
  mmss = substr(normal,10,4);
  mmss = tranwrd(mmss,'FF','00');
cards;
PT14M
PT2M
P0DT14M
2023-01-02T01:02:03
2023-11-22T01:02:03
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2023 03:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908958#M358610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-20T03:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time is8601. format to MM:SS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908960#M358611</link>
      <description>&lt;P&gt;Thank you for the suggestions. Just an update on your questions: Our variables only have the minutes and seconds. This is the playtime of a video. And all the videos are less than an hour, so, it never gets into hours; if no one watches the video then duration is missing by default in the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I played a bit with the following code.&amp;nbsp; Please suggest to me if it has any pitfalls in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
  input duration $20.;
cards;
PT14M
PT2M
;
run;

data want;
set have;
 	if duration  ne ''  then duration = strip(put((input(substr(duration, 3, length(duration)-3), best.)*60),mmss5.));
	duration = ifc(length(duration) =5, duration,"0"||strip(duration)); 
	if duration = '0' then duration ='';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2023 04:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908960#M358611</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-12-20T04:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time is8601. format to MM:SS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908962#M358613</link>
      <description>&lt;P&gt;If you are only using a subset of ISO8601 then you should be able to use simpler methods to parse the strings.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should increase your examples to cover all of the possible types of values to make sure your algorithm can handle the values you get.&amp;nbsp; For example do you ever have minutes and seconds?&amp;nbsp; Seconds only?&amp;nbsp; Do you always have PT as the first two characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 06:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908962#M358613</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-20T06:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time is8601. format to MM:SS format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908964#M358615</link>
      <description>&lt;P&gt;For example you might use SCAN() to parse the string into the parts that should have digit strings and convert them into numbers you can convert into an actual TIME value.&amp;nbsp; Then you can convert that into you MMSS string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input duration $20.;
  if duration=:'PT' then do;
     time=input('0'||scan(duration,-3,'PTMS'),32.)*60
         +input('0'||scan(duration,-2,'PTMS'),32.)
     ;
     if char(duration,length(duration))='M' then time=time*60;
     mmss=substr(put(time,B8601TM6.),3);
  end;
  format time time12.;
cards;
PT14M
PT2M
PT1M25S
PT65S
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Dec 2023 06:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-is8601-format-to-MM-SS-format/m-p/908964#M358615</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-20T06:31:27Z</dc:date>
    </item>
  </channel>
</rss>

