<?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: Separate a string between two strings in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712788#M27078</link>
    <description>&lt;P&gt;Thank you Members, All the solutions worked&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 16:57:45 GMT</pubDate>
    <dc:creator>SAS_New_User1</dc:creator>
    <dc:date>2021-01-20T16:57:45Z</dc:date>
    <item>
      <title>Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712536#M27061</link>
      <description>&lt;P&gt;I have a string&amp;nbsp;&lt;/P&gt;&lt;P&gt;example 1: abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:&lt;/P&gt;&lt;P&gt;example 2:&lt;/P&gt;&lt;P&gt;hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract any string between the 1st START and STOP strings i.e. the output should look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output 1:&lt;/P&gt;&lt;P&gt;41A:45583993:START:60A:6483829992&lt;/P&gt;&lt;P&gt;Output 2:&lt;/P&gt;&lt;P&gt;71A:274765765:START:84A:26357457454&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I resolve this? I tried using SCAN function but with no luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 22:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712536#M27061</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-19T22:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712543#M27062</link>
      <description>&lt;P&gt;You can use the INDEX function to find the first position of one string within another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input string :$100.;
datalines;
abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:
hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef
;

data want;
  set have;
  startpos=index(string,'START:');
  endpos  =index(string,':STOP:');
  length newstring $ 100;
  newstring = substr(string,startpos+6,endpos-(startpos+7));
run;&lt;/PRE&gt;
&lt;P&gt;I left the variables startpos and endpos as examples. The startpos has to be shifted because is the first position of the "START:" so you need to add 6 characters, the length of "START:" to get the first character following the first occurence. The endpos needs to be adjusted as it is the original position in the string and you need to remove the characters that come before the START:.&lt;/P&gt;
&lt;P&gt;The INDEX function will return 0 for the position if the string is not found. Best practice would be to do the SUBSTR only when both Statpos and Endpos are greater than 0.&lt;/P&gt;
&lt;P&gt;You don't say what to do if you have a Start without a Stop. That should be considered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 23:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712543#M27062</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-19T23:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712548#M27063</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
length eg $500;
eg='abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73';
output;
eg='hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef';
output;
run;

data want;
 set have;
 length want $200;
 n=index(eg,'START')+6;
 want=substr(eg,n,index(eg,'STOP')-n-1);
 drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2021 23:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712548#M27063</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-19T23:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712647#M27074</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input string :$100.;
datalines;
abcdefgs:456:fdkweu/:START:41A:45583993:START:60A:6483829992:STOP:59:hagdsu2381ygu:73:
hsdgsdgcj:64:54:adcg6edd:START:71A:274765765:START:84A:26357457454:STOP:59:2237fdguef
;
data want;
 set have;
 pid=prxparse('/start.+stop/i');
 if prxmatch(pid,string) then do;
   call prxsubstr(pid,string,p,l);
   want=substr(string,p+6,l-11);
 end;
 drop pid p l;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 12:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712647#M27074</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-20T12:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712742#M27075</link>
      <description>&lt;P&gt;Or you simply loop through the string (the method for using SCAN):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length newstring $100;
_flag = 0;
do _i = 1 to countw(string,":");
  _word = scan(string,_i,":");
  if _word = "START" then _flag = 1;
  else if _word = "STOP" then _flag = 0;
  else if _flag then newstring = catx(":",newstring,_word);
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2021 15:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712742#M27075</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-20T15:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Separate a string between two strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712788#M27078</link>
      <description>&lt;P&gt;Thank you Members, All the solutions worked&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 16:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Separate-a-string-between-two-strings/m-p/712788#M27078</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-20T16:57:45Z</dc:date>
    </item>
  </channel>
</rss>

