<?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: More elegant way to extract a substring between two delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/969011#M376704</link>
    <description>&lt;P&gt;I would like to mention that if you have data like this:&lt;/P&gt;
&lt;PRE&gt;text = 'this is some text. Destination(s): more text.xxxxx.';
&lt;/PRE&gt;
&lt;P&gt;And you could get this :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1749884999960.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107815iA5A0C4A264C7C795/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1749884999960.png" alt="Ksharp_0-1749884999960.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It that what you are looking for?&lt;/P&gt;
&lt;P&gt;If I were you ,I would prefer to use Tom 's code .&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jun 2025 07:10:55 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-06-14T07:10:55Z</dc:date>
    <item>
      <title>More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968880#M376663</link>
      <description>&lt;P&gt;I am trying to extract a substring from a field that has up to 2000 characters. I need to capture whatever is between "Destination(s):" and "."&amp;nbsp; The following works, but is there a more elegant way to do this? I feel like I'm missing something obvious.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Case&lt;BR /&gt;When FIND(t1.Comment_ID,"Destination(s):") &amp;gt; 1 then STRIP(SUBSTR(t1.Comment_ID,FIND(t1.Comment_ID,"Destination(s):")+16,FIND(SUBSTR(t1.Comment_ID,FIND(t1.Comment_ID,"Destination(s):")+16,200),".")-1))&lt;BR /&gt;Else ""&lt;BR /&gt;End&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Lisa&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 16:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968880#M376663</guid>
      <dc:creator>LisaSklar</dc:creator>
      <dc:date>2025-06-12T16:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968896#M376676</link>
      <description>&lt;P&gt;Another alternative is to use PRXPARSE. Here is an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data parse_data;
retain re;
text = 'this is some text. Destination(s): more text.';
if(_N_ = 1) then re = PRXPARSE("/(?&amp;lt;=Destination\(s\):)(.*)(?=\.)/io");
if(prxmatch(re, text) ) then new_text = strip(prxposn(re, 1, text) );
drop re;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jun 2025 17:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968896#M376676</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-12T17:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968910#M376683</link>
      <description>&lt;P&gt;One simple thing to make it easier is to use a data step instead of SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SQL you could store the location into another variable and use the CALCULATED keyword to reference it.&lt;/P&gt;
&lt;P&gt;If you want everything up to a period then use SCAN().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;....
  find(t1.Comment_ID,"Destination(s):") as loc
, case when (calculated loc &amp;gt; 0) 
       then left(scan(substr(t1.Comment_ID,calculated loc+16),1,'.'))
       else ' ' 
  end as WANT length=2000
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 18:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968910#M376683</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-12T18:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968947#M376698</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=x;
filename x temp;
parmcards;
whatever Destination(s): and and .  The following and works, but is there a mor  Destination(s): or or .  The following 
whatever Destination(s): and and .  The following and works, but is there a mor  Destination(s): or or .  The following 
;

data want;
infile x length=len;
input x $varying2000. len;
n+1;
pid=prxparse('/Destination\(s\):.+?\./i');
s=1;e=length(x);
call prxnext(pid,s,e,x,p,l);
do while(p&amp;gt;0);
 want=scan(substr(x,p,l),2,':.');
 output;
 call prxnext(pid,s,e,x,p,l);
end;
keep n want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1749778139181.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107803iABB1EEB2B7F28481/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1749778139181.png" alt="Ksharp_0-1749778139181.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 01:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968947#M376698</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-06-13T01:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968976#M376701</link>
      <description>&lt;P&gt;Thanks, this is along the lines of what I was, it just totally slipped my mind. Appreciate it!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 12:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/968976#M376701</guid>
      <dc:creator>LisaSklar</dc:creator>
      <dc:date>2025-06-13T12:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: More elegant way to extract a substring between two delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/969011#M376704</link>
      <description>&lt;P&gt;I would like to mention that if you have data like this:&lt;/P&gt;
&lt;PRE&gt;text = 'this is some text. Destination(s): more text.xxxxx.';
&lt;/PRE&gt;
&lt;P&gt;And you could get this :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1749884999960.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107815iA5A0C4A264C7C795/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1749884999960.png" alt="Ksharp_0-1749884999960.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It that what you are looking for?&lt;/P&gt;
&lt;P&gt;If I were you ,I would prefer to use Tom 's code .&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jun 2025 07:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-elegant-way-to-extract-a-substring-between-two-delimiters/m-p/969011#M376704</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-06-14T07:10:55Z</dc:date>
    </item>
  </channel>
</rss>

