<?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: How do i use Perl Regular Expressions for ISO 8601 durations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800411#M314849</link>
    <description>&lt;P&gt;Patrick,&amp;nbsp;Thanks&lt;/P&gt;&lt;P&gt;There are some mistakes in the previous understanding of ISO duration, Like "P1.4Y2M", "P2MT30.5M3S" make no sense, etc.&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2022 03:24:22 GMT</pubDate>
    <dc:creator>tri_h</dc:creator>
    <dc:date>2022-03-06T03:24:22Z</dc:date>
    <item>
      <title>How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800101#M314696</link>
      <description>&lt;P&gt;a data like:&lt;/P&gt;&lt;P&gt;data _tstdata;&lt;BR /&gt;length Duration $ 20;&lt;BR /&gt;input Duration $;&lt;BR /&gt;datalines;&lt;BR /&gt;P2Y&lt;BR /&gt;P10W&lt;BR /&gt;P3M14D&lt;BR /&gt;P3D&lt;BR /&gt;P6M17DT3H&lt;BR /&gt;P14DT7H57M&lt;BR /&gt;PT42M18S&lt;BR /&gt;PT0.5H&lt;BR /&gt;P5DT12.25H&lt;BR /&gt;P4.5W&lt;BR /&gt;P1Y&lt;BR /&gt;P1.4Y&lt;BR /&gt;P1.4Y2M&lt;BR /&gt;P14Y2.5M&lt;BR /&gt;P14Y2.5MT1M&lt;BR /&gt;P2MT30M&lt;BR /&gt;P2MT30.5M&lt;BR /&gt;P2MT30.5M3S&lt;BR /&gt;PT6H&lt;BR /&gt;PT6.5H&lt;BR /&gt;PT6.5H12S&lt;BR /&gt;P5W&lt;BR /&gt;P5.2W&lt;BR /&gt;P5.2W1D&lt;BR /&gt;P3Y29DT4H35M59S&lt;BR /&gt;P1Y1M1DT2H12M34.23S&lt;/P&gt;&lt;P&gt;P&lt;BR /&gt;PT&lt;BR /&gt;P3MT&lt;BR /&gt;PARALLEL&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;and the last 4 records are not a ISO 8601 duration format.&lt;/P&gt;&lt;P&gt;thanks for helping&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 10:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800101#M314696</guid>
      <dc:creator>tri_h</dc:creator>
      <dc:date>2022-03-04T10:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800109#M314701</link>
      <description>&lt;P&gt;A bit more explanation wouldn't hurt. What's the desired outcome? May-be add some code that creates a Want table and some narrative explaining the logic required to get from Have to Want?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 11:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800109#M314701</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-04T11:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800162#M314728</link>
      <description>&lt;P&gt;SORRY, i do tried some syntax like:&lt;/P&gt;&lt;DIV&gt;data tst;&lt;/DIV&gt;&lt;DIV&gt;set _tstdata;&lt;/DIV&gt;&lt;DIV&gt;if prxmatch("/^P((\d+\.)?\d+[YMWD]$)?((\d+\.)?\d+Y$)?((\d+\.)?\d+M$)?((\d+\.)?\d+W$)?((\d+\.)?\d+D$)?(T((\d+\.)?\d+[HMS]$)((\d+\.)?\d+H$)?((\d+\.)?\d+M$)?((\d+\.)?\d+S$)?)?/", Duration)&amp;nbsp;then Data_Type='durationDatetime';&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;run;&lt;/DIV&gt;&lt;DIV&gt;even I add "&lt;SPAN&gt;&lt;SPAN&gt;and substrn(Duration, lengthn(Duration)) not in ('P', 'T')" at the if statement, but i still can't aviod the string of "P*" been&amp;nbsp;recognized as the ISO 8601&amp;nbsp;DURATION FORMAT(WHICH IS WRONG) ,&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;is there any&amp;nbsp;possibility that&amp;nbsp; i can use only 1 patern to recognized the ISO 8601 duration?&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 04 Mar 2022 14:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800162#M314728</guid>
      <dc:creator>tri_h</dc:creator>
      <dc:date>2022-03-04T14:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800201#M314741</link>
      <description>&lt;P&gt;Did you try to adapt the marked answer from this SO question?&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/32044846/regex-for-iso-8601-durations" target="_blank"&gt;https://stackoverflow.com/questions/32044846/regex-for-iso-8601-durations&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 15:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800201#M314741</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-04T15:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800327#M314798</link>
      <description>&lt;P&gt;yes, the searching found stackflow, but their codes doesn't work at SAS prxmatch functions, when i reference there solution:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;^P(?=\d+[YMWD])(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d+[HMS])(\d+H)?(\d+M)?(\d+S)?)?$&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as the pattern, i got no an empty column of data_type, i'm not&amp;nbsp;familiar enough with perl regular expression~&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 11:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800327#M314798</guid>
      <dc:creator>tri_h</dc:creator>
      <dc:date>2022-03-05T11:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800383#M314827</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261908"&gt;@tri_h&lt;/a&gt;&amp;nbsp;I've never worked with iso duration formats but just by searching a bit in the SAS docu there are some informat, formats and - best of all - a call routine that deal with such iso duration formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've also implemented the RegEx found under the link&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;provided. There are some differences between the different options and some further investigation will be required which one returns the "correct" result.&lt;/P&gt;
&lt;P&gt;Below sample code should point you into the right direction. I believe ideally you can use the SAS call routine as this will give you the duration as a count of seconds which you then could use directly in conjunction with SAS Datetime values (like: end_dttm = start_dttm+duration_in_sec;).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input iso_dur $50.;
  datalines;
P2Y
P10W
P3M14D
P3D
P6M17DT3H
P14DT7H57M
PT42M18S
PT0.5H
P5DT12.25H
P4.5W
P1Y
P1.4Y
P1.4Y2M
P14Y2.5M
P14Y2.5MT1M
P2MT30M
P2MT30.5M
P2MT30.5M3S
PT6H
PT6.5H
PT6.5H12S
P5W
P5.2W
P5.2W1D
P3Y29DT4H35M59S
P1Y1M1DT2H12M34.23S

P
PT
P3MT
PARALLEL
;

data demo;
  set have;

  inf_N8601B=input(strip(iso_dur),$N8601B.);

  inf_N8601E=input(strip(iso_dur),$N8601E.);
  inf_N8601E_fmt=put(inf_N8601E,$N8601E.);

  call is8601_convert('du', 'du', iso_dur, dur_in_sec);

  regex_match_flg=prxmatch('/^P(?=\d+[YMWD])(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d+[HMS])(\d+H)?(\d+M)?(\d+S)?)?$/oi',strip(iso_dur));
  inf_N8601E_fmt_match_flg= substr(inf_N8601E_fmt,1,1) not in (' ','*');
  dur_in_sec_match_flg = not missing(dur_in_sec);
run;

proc print data=demo;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1646522510339.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69184i689FC7859B263A16/image-size/large?v=v2&amp;amp;px=999" role="button" title="Patrick_0-1646522510339.png" alt="Patrick_0-1646522510339.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 23:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800383#M314827</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-05T23:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800411#M314849</link>
      <description>&lt;P&gt;Patrick,&amp;nbsp;Thanks&lt;/P&gt;&lt;P&gt;There are some mistakes in the previous understanding of ISO duration, Like "P1.4Y2M", "P2MT30.5M3S" make no sense, etc.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 03:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800411#M314849</guid>
      <dc:creator>tri_h</dc:creator>
      <dc:date>2022-03-06T03:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do i use Perl Regular Expressions for ISO 8601 durations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800415#M314853</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/261908"&gt;@tri_h&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Patrick,&amp;nbsp;Thanks&lt;/P&gt;
&lt;P&gt;There are some mistakes in the previous understanding of ISO duration, Like "P1.4Y2M", "P2MT30.5M3S" make no sense, etc.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;P1.4Y2M got by all options identified as invalid.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P14Y2.5M though got only marked as invalid by the RegEx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like the SAS call routine does a fine job. You will just have to decide how you want to treat a missing - the call routine returns zero seconds and not missing.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 04:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-use-Perl-Regular-Expressions-for-ISO-8601-durations/m-p/800415#M314853</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-06T04:10:06Z</dc:date>
    </item>
  </channel>
</rss>

