<?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 to find the nth string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701922#M214964</link>
    <description>Please expand your sample data to include records where the already provided solutions did not work. Otherwise you'll get the same answers again.&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701893" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701893&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 26 Nov 2020 21:40:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-11-26T21:40:58Z</dc:date>
    <item>
      <title>how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701921#M214963</link>
      <description>&lt;P&gt;I need to extract the time range and location from a variable "Itemproperties".&amp;nbsp; I'm having difficulty bc some location have 2 delimerters ("@") and others will have 1. Also the substr would not work bc the position of the characters are not consistent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitmonTran_1-1606426419690.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52029iB0737F8D79624DF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HitmonTran_1-1606426419690.png" alt="HitmonTran_1-1606426419690.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;BLOCKQUOTE&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Itemproperties&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Pickup Details:6. 11/21 SAT&amp;nbsp; &amp;nbsp; 4:40 - 5:00 @ Mountain View @ Ranch 99&lt;/P&gt;&lt;P&gt;Pickup Details:6. 11/21 SAT 5:30 - 5:50 @ Cupertino&lt;/P&gt;&lt;P&gt;Pickup Details:5.&amp;nbsp; &amp;nbsp; &amp;nbsp; 10/23 FRI 4:40 - 5:00 @&amp;nbsp; &amp;nbsp; &amp;nbsp;W. SJ @&amp;nbsp; &amp;nbsp;Starbucks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;location&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;time&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Mountain View&amp;nbsp;@ Ranch 99&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4:40 - 5:00&lt;/P&gt;&lt;P&gt;Cupertino&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5:30 - 5:50&lt;/P&gt;&lt;P&gt;W. SJ @ Starbucks&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;4:40 - 5:00&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 26 Nov 2020 21:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701921#M214963</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-11-26T21:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701922#M214964</link>
      <description>Please expand your sample data to include records where the already provided solutions did not work. Otherwise you'll get the same answers again.&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701893" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701893&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Nov 2020 21:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701922#M214964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-26T21:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701925#M214966</link>
      <description>i did provide the sample data above. it is different from the previous version with more inconsistent spaces.</description>
      <pubDate>Thu, 26 Nov 2020 21:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701925#M214966</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-11-26T21:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701932#M214968</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input Itemproperties  $100. ;
cards;
Pickup Details:6. 11/21 SAT    4:40 - 5:00 @ Mountain View @ Ranch 99
Pickup Details:6. 11/21 SAT 5:30 - 5:50 @ Cupertino
Pickup Details:5.      10/23 FRI 4:40 - 5:00 @     W. SJ @ Starbucks
;
run;


data want;
	set have;
	
	location=strip(substr(Itemproperties,index(Itemproperties,'@')+1));

/* Regular Expression - Definition */
/* \d matches a digit (equal to [0-9]) */
/* : matches the character : literally  */
/* \d+ matches a digit (equal to [0-9]) */
/* + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) */
/* \s matches any whitespace character  */
/* - matches the character - literally  */
/* \s matches any whitespace character  */
/* \d matches a digit (equal to [0-9]) */
/* : matches the character : literally  */
/* \d+ matches a digit (equal to [0-9]) */
/* + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy) */
	
	patternID = prxparse('/(\d:\d+\s-\s\d:\d+)/');
	
	call prxsubstr(patternID, Itemproperties, position, length);
	
	if position &amp;gt; 0 then time=substr(Itemproperties,position,length);

	


drop patternID position length;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Nov 2020 22:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701932#M214968</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-11-26T22:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701945#M214977</link>
      <description>&lt;P&gt;Many ways to do this. Here are 2 examples. Arrange to suit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
  infile cards truncover;
  input ITEMPROPERTIES  $100. ;
  TIME1=scan(ITEMPROPERTIES,5,' ')||'-'||scan(ITEMPROPERTIES,7,' ');
  LOC1 =substr(ITEMPROPERTIES,index(ITEMPROPERTIES,'@')+1);
  TIME2=prxchange('s/.*(\d\d?:\d\d[ -]{1,3}\d\d?:\d\d).*/\1/',1,ITEMPROPERTIES);
  LOC2 =prxchange('s/.*?@ *(.*)/\1/',1,ITEMPROPERTIES);
cards;                                     
Pickup Details:6. 11/21 SAT    4:40 - 5:00 @ Mountain View @ Ranch 99
Pickup Details:6. 11/21 SAT 5:30 - 5:50 @ Cupertino
Pickup Details:5.      10/23 FRI 4:40 - 5:00 @     W. SJ @ Starbucks
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.HAVE" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;ITEMPROPERTIES&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;TIME1&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;LOC1&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;TIME2&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;LOC2&lt;/FONT&gt;&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Pickup Details:6. 11/21 SAT 4:40 - 5:00 @ Mountain View @ Ranch 99&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;4:40-5:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Mountain View @ Ranch 99&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;4:40 - 5:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Mountain View @ Ranch 99&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Pickup Details:6. 11/21 SAT 5:30 - 5:50 @ Cupertino&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;5:30-5:50&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Cupertino&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;5:30 - 5:50&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Cupertino&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;Pickup Details:5. 10/23 FRI 4:40 - 5:00 @ W. SJ @ Starbucks&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;4:40-5:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;W. SJ @ Starbucks&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;4:40 - 5:00&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT size="2"&gt;W. SJ @ Starbucks&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 01:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701945#M214977</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-27T01:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701946#M214978</link>
      <description>&lt;P&gt;Also note how more flexible the RegEx is. It can parse this data without issue (spaces removed around and inside time, and after @).&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Pickup Details:5. 10/23 FRI4:40-5:00@W. SJ @ Starbucks&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 02:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701946#M214978</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-27T02:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the nth string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701956#M214982</link>
      <description>thanks, your code worked as well. happy holidays!</description>
      <pubDate>Fri, 27 Nov 2020 04:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-nth-string/m-p/701956#M214982</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-11-27T04:24:40Z</dc:date>
    </item>
  </channel>
</rss>

