<?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: Function to Fetch n words from a variable separated by a Delimiter? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116671#M259394</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;call scan() is what you are looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data _null_;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varlist='Hello$Test$System$SAS';
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call scan(varlist,4,pos,len,'$');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=substr(varlist,1,pos-2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put key=;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Apr 2013 10:02:00 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2013-04-23T10:02:00Z</dc:date>
    <item>
      <title>Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116668#M259391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varlist='Hello$Test$System$SAS';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=scan(varlist,2,'$');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put key=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above code, the output would be key=Test since I have given 2 in the scan function.&lt;/P&gt;&lt;P&gt;But my requirement is I should get output as key=Hello$Test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I pass 3 ie. [key=scan(varlist,3,'$');] , then my output should be key=Hello$Test$System.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any function in SAS to extract the word as like SUBSTR from n no. of words specfied by a Delimiter?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;BR /&gt;Surae.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 06:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116668#M259391</guid>
      <dc:creator>suraestar</dc:creator>
      <dc:date>2013-04-23T06:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116669#M259392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A combination of SUBSTR() and INDEXW() should do the trick.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 08:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116669#M259392</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-04-23T08:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116670#M259393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the SUBSTR function only to get the output...Why it is not coming by using SUBSTR functio ???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; varlist = 'Hello$Test$System$SAS';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; key = substr(varlist,1,10);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put key =;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;-Urvish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 09:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116670#M259393</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-04-23T09:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116671#M259394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;call scan() is what you are looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data _null_;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varlist='Hello$Test$System$SAS';
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call scan(varlist,4,pos,len,'$');
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=substr(varlist,1,pos-2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put key=;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 10:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116671#M259394</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-04-23T10:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116672#M259395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course Ksharp's solution is by far the most elegant . But If you want to taste some flavor of PRX, here is one possibility:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let n=2;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; varlist = 'Hello$Test$System$SAS';&lt;/P&gt;&lt;P&gt;ptn=prxparse('/[^\$]+/');&lt;/P&gt;&lt;P&gt;start=1;stop=length(varlist);&lt;/P&gt;&lt;P&gt;call prxnext(ptn,start,stop,varlist,pos,len);&lt;/P&gt;&lt;P&gt;do i=1 to &amp;amp;n.-1 while (pos &amp;gt; 0);&lt;/P&gt;&lt;P&gt;&amp;nbsp; call prxnext(ptn,start,stop,varlist,pos,len);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;varlist_want=substr(varlist,1,pos+len-1);&lt;/P&gt;&lt;P&gt;put varlist_want=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 13:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116672#M259395</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-23T13:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116673#M259396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your ideas.&amp;nbsp; and i get the expected output from Hai.Kuo..&lt;/P&gt;&lt;P&gt;and Ksharp code was helped in some other logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But is there any other way to do it more simpler.??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Surae..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2013 05:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116673#M259396</guid>
      <dc:creator>suraestar</dc:creator>
      <dc:date>2013-04-24T05:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116674#M259397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, suraestar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;A simple method&lt;/SPAN&gt;.You can try it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varlist='Hello$Test$System$SAS';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key=prxchange('s/(.+?)(\$)(.+?)\$(.+)/$1$2$3/',-1,varlist);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put key=;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Apr 2013 16:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116674#M259397</guid>
      <dc:creator>Xianhua_zeng</dc:creator>
      <dc:date>2013-04-25T16:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Function to Fetch n words from a variable separated by a Delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116675#M259398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Thanks,but this seems to be little pre-processing may require. If my varlist exceeds more than 5 words, then I should rebuild the prxchange parse code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 04:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Function-to-Fetch-n-words-from-a-variable-separated-by-a/m-p/116675#M259398</guid>
      <dc:creator>suraestar</dc:creator>
      <dc:date>2013-04-26T04:16:21Z</dc:date>
    </item>
  </channel>
</rss>

