<?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 Extracting sub-string/variables based on conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542012#M149754</link>
    <description>&lt;P&gt;This is an SQL condition for joining two datasets separated in a variable text as below.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;text="AB.name = dsn.pname and AB.ID = dsn.varID and AB.custid=dsn.customerid" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to pick the variables from dataset &lt;STRONG&gt;dsn&lt;/STRONG&gt; only and store all the &lt;STRONG&gt;dsn&lt;/STRONG&gt; variables from this condition into another variable. I have tried the following code using array and do loop , but something is missing from the second iteration. Variables are not created &lt;BR /&gt;from second iteration, as a result values are also not created. May i know what is wrong in this or is their any other short cut method to &lt;BR /&gt;generate this . I want the final output like this.(all variables in DSN dataset presnet in the text condition are separated)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Output=pname varid customerid&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;set text ;&lt;BR /&gt;text="AB.name = dsn.pname and AB.ID = dsn.varID and AB.custid=dsn.customerid";&lt;BR /&gt;mod='i';&lt;BR /&gt;domain="dsn";&lt;BR /&gt;cnt=count(text,strip(domain));&lt;BR /&gt;array str {3} $40. ;&lt;BR /&gt;array fdf {3};&lt;BR /&gt;do i = 1 to 3 ; &lt;BR /&gt;fdf[i]=find(text,strip(domain),mod,fdf[i]+i) ;&lt;BR /&gt;str{i}=scan(substr(text,fdf(i)+1),2,". ","M") ; &lt;BR /&gt;end ;&lt;BR /&gt;outvar=catx(' ',str:) ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2019 13:44:24 GMT</pubDate>
    <dc:creator>keen_sas</dc:creator>
    <dc:date>2019-03-11T13:44:24Z</dc:date>
    <item>
      <title>Extracting sub-string/variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542012#M149754</link>
      <description>&lt;P&gt;This is an SQL condition for joining two datasets separated in a variable text as below.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;text="AB.name = dsn.pname and AB.ID = dsn.varID and AB.custid=dsn.customerid" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to pick the variables from dataset &lt;STRONG&gt;dsn&lt;/STRONG&gt; only and store all the &lt;STRONG&gt;dsn&lt;/STRONG&gt; variables from this condition into another variable. I have tried the following code using array and do loop , but something is missing from the second iteration. Variables are not created &lt;BR /&gt;from second iteration, as a result values are also not created. May i know what is wrong in this or is their any other short cut method to &lt;BR /&gt;generate this . I want the final output like this.(all variables in DSN dataset presnet in the text condition are separated)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Output=pname varid customerid&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;set text ;&lt;BR /&gt;text="AB.name = dsn.pname and AB.ID = dsn.varID and AB.custid=dsn.customerid";&lt;BR /&gt;mod='i';&lt;BR /&gt;domain="dsn";&lt;BR /&gt;cnt=count(text,strip(domain));&lt;BR /&gt;array str {3} $40. ;&lt;BR /&gt;array fdf {3};&lt;BR /&gt;do i = 1 to 3 ; &lt;BR /&gt;fdf[i]=find(text,strip(domain),mod,fdf[i]+i) ;&lt;BR /&gt;str{i}=scan(substr(text,fdf(i)+1),2,". ","M") ; &lt;BR /&gt;end ;&lt;BR /&gt;outvar=catx(' ',str:) ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 13:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542012#M149754</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-03-11T13:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sub-string/variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542027#M149760</link>
      <description>&lt;P&gt;Pearl Regular Expressions are probably the easiest, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  text="AB.name = dsn.pname and AB.ID = dsn.varID and AB.custid=dsn.customerid";
  prxid=prxparse('/(?&amp;lt;=\bdsn\.)\S*/i');
  start=1;
  pos=0;
  len=0;
  do until(0);
    call prxnext(prxid,start,-1,text,pos,len);
    if len=0 then leave;
    outvar=substr(text,pos,len);
    output;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An explanation of the search string in PRXPARSE: "(?&amp;lt;=\bdsn\.)" is a look-behind assertion: it has to be there but is not included in the output. The meaning is a word boundary (\b) plus the text "dsn." ("." has to be escaped with a "\"). After that comes "\S*", meaning zero or more non whitespace characters, which is the string you are looking for. the final "i" just means that the search is case independent, the search will find "DSN." as well as "dsn.".&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 14:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542027#M149760</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-11T14:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sub-string/variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542128#M149793</link>
      <description>Thank you S_Lassen for quick response. I have one query with respect to PRXPARSE. If i am not sure what exactly is the name of the dataset , the name of the dataset anything  between A- Z and sometimes it is inclusive of _ also like AB_C..In general if i want to include all the alphabets along with _ how do i parse these in PRXPARSE. When i try to include all of the alphabets its not working. Can you please suggest.</description>
      <pubDate>Mon, 11 Mar 2019 17:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542128#M149793</guid>
      <dc:creator>keen_sas</dc:creator>
      <dc:date>2019-03-11T17:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sub-string/variables based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542296#M149834</link>
      <description>&lt;P&gt;I assumed that you could just look for non-whitespace, but of course your SQL expression may look like e.g. "a.col1=dsn.col4&amp;amp;a.col3...", without whitespace. So you may want to use "\w" (word character) instead of "\S" (non whitespace). You could also check for the first character being non-numeric, but is that really necessary, if your input is valid SQL code?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 08:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sub-string-variables-based-on-conditions/m-p/542296#M149834</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-12T08:51:30Z</dc:date>
    </item>
  </channel>
</rss>

