<?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 Extract part of a string in reference to a Key word  and positional delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-part-of-a-string-in-reference-to-a-Key-word-and/m-p/444178#M282923</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I am trying to extract part of a string available between 3rd and 4th pipe following a key word "ABC". Can anybody please assist me to move forward.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 ABC|X01|X02|2001|DEF|X01|X02
102 X02|ABC|X001|X002|2002|DEF
103 X04|X02|ABC|X0001|X0002|2003|DEF|X01|X02
104 X05|X02|X02|ABC|X00001|X00002|2004|DEF
105 X02|ABC|X01|X02|2005|DEF
;
RUN;


data WANT;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 2001
102 2002
103 2003
104 2004
105 2005
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Thank you in advance for your kind guidance.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Mar 2018 16:30:32 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2018-03-09T16:30:32Z</dc:date>
    <item>
      <title>Extract part of a string in reference to a Key word  and positional delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-part-of-a-string-in-reference-to-a-Key-word-and/m-p/444178#M282923</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am trying to extract part of a string available between 3rd and 4th pipe following a key word "ABC". Can anybody please assist me to move forward.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 ABC|X01|X02|2001|DEF|X01|X02
102 X02|ABC|X001|X002|2002|DEF
103 X04|X02|ABC|X0001|X0002|2003|DEF|X01|X02
104 X05|X02|X02|ABC|X00001|X00002|2004|DEF
105 X02|ABC|X01|X02|2005|DEF
;
RUN;


data WANT;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 2001
102 2002
103 2003
104 2004
105 2005
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Thank you in advance for your kind guidance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 16:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-part-of-a-string-in-reference-to-a-Key-word-and/m-p/444178#M282923</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2018-03-09T16:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract part of a string in reference to a Key word  and positional delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-part-of-a-string-in-reference-to-a-Key-word-and/m-p/444185#M282924</link>
      <description>&lt;P&gt;Why do you have multiple data items in one variable, this is not a good method of storing or processing data - hence why you have a few questions on this topic.&amp;nbsp; Split your data up.&amp;nbsp; As for your question, its exactly the same as before, except you have another substr():&lt;/P&gt;
&lt;PRE&gt;data HAVE;&lt;BR /&gt;length id $3 comment $50 ;&lt;BR /&gt;input id comment $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;101 ABC|X01|X02|2001|DEF|X01|X02&lt;BR /&gt;102 X02|ABC|X001|X002|2002|DEF&lt;BR /&gt;103 X04|X02|ABC|X0001|X0002|2003|DEF|X01|X02&lt;BR /&gt;104 X05|X02|X02|ABC|X00001|X00002|2004|DEF&lt;BR /&gt;105 X02|ABC|X01|X02|2005|DEF&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data want (drop=ext_str);&lt;BR /&gt; set have;&lt;BR /&gt; length ext_str want $200;&lt;BR /&gt; ext_str=substr(comment,index(comment,"ABC")+3);&lt;BR /&gt; want=scan(ext_str,3,"|");&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;note, you can combine the two steps.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 16:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-part-of-a-string-in-reference-to-a-Key-word-and/m-p/444185#M282924</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-09T16:50:20Z</dc:date>
    </item>
  </channel>
</rss>

