<?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: Parse a string with words as delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/539110#M148477</link>
    <description>&lt;P&gt;thats awesome. thanks&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 20:13:41 GMT</pubDate>
    <dc:creator>34reqrwe</dc:creator>
    <dc:date>2019-02-27T20:13:41Z</dc:date>
    <item>
      <title>Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538763#M148327</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a long text string which I would like to do the following.&lt;/P&gt;&lt;P&gt;1) find the position of each occurence of the text 'cn='&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) extract the text occuring after 'cn=' up until the next comma&lt;/P&gt;&lt;P&gt;3) for each occurence of 'cn=' within the string, create a new column with a 1/0 (or 1/missing) indicator . That column would take the name of the resulting text in 2) .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example code&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length string $200.;
	id=111;
	string = 'xxx,xxcn=test1,yyy,zz,cn=test2,dfd'; output;
	id=222;
	string = 'xadfds , xx,xxcn=test3,yyy,zz,cn=test2,dfd'; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;an example of what I want&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	id = 111 ; test1 = 1 ; test2 = 1 ; test3=.; output;
	id = 222; test1 =  . ; test2 = 1; test3 =1; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 19:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538763#M148327</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-02-26T19:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538797#M148345</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
	length string $200.;
	id=111;
	string = 'xxx,xxcn=test1,yyy,zz,cn=test2,dfd'; output;
	id=222;
	string = 'xadfds , xx,xxcn=test3,yyy,zz,cn=test2,dfd'; output;
run;

data _null_;
set have end=lr;
do pos=find(string,'cn=') by 0 while(pos);
k=input(substr(string,pos+7,1),8.);
m=max(m,k);
pos = find(string, 'cn=', pos + 8) ; 
end;
max=max(m,max);
retain max;
if lr;
call symputx('n',max);
run;

%put &amp;amp;n;

data want;
set have;
array test(&amp;amp;n);
do pos=find(string,'cn=') by 0 while(pos);
t=substr(string,pos+3,5);
 do i=1 to dim(test);
	if vname(test(i))=t then test(i)=1;
end;
pos = find(string, 'cn=', pos + 8) ; 
end;
keep id test:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 20:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538797#M148345</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-26T20:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538808#M148353</link>
      <description>&lt;P&gt;Thanks very much for taking the time to look at this . I should have been more prescriptive in my initial example and mentioned that the length of the text after 'cn=' can be a different length each time&amp;nbsp; . e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length string $200.;
	id=111;
	string = 'xxx,xxcn=test1,yyy,zz,cn=test2,dfd'; output;
	id=222;
	string = 'xadfds , xx,xxcn=test3,yyy,zz,cn=test2,dfd'; output;
	id=333;
	string = 'xadfds , xx,xxcn=test3,yyy,zz,cn=somthingdiff,dfd'; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I can use your example to get what I need thanks&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 21:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538808#M148353</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-02-26T21:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538811#M148356</link>
      <description>&lt;P&gt;Yes please post the best representative sample. Typically that happens a lot which I call ding dong(back and forth)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 21:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538811#M148356</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-26T21:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538949#M148417</link>
      <description>&lt;PRE&gt;data have;
	length string $200.;
	id=111;
	string = 'xxx,xxcn=test1,yyy,zz,cn=test2,dfd'; output;
	id=222;
	string = 'xadfds , xx,xxcn=test3,yyy,zz,cn=test2,dfd'; output;
run;
data temp;
 set have;
retain value 1;
pid=prxparse('/(?&amp;lt;=cn=)\w+/');
s=1;e=length(string);
call prxnext(pid,s,e,string,p,l);
do while(p&amp;gt;0);
 temp=substr(string,p,l);output;
 call prxnext(pid,s,e,string,p,l);
end;
drop pid s e p l string;
run;
proc transpose data=temp out=want;
by id;
id temp;
var value;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 13:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/538949#M148417</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-02-27T13:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a string with words as delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/539110#M148477</link>
      <description>&lt;P&gt;thats awesome. thanks&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 20:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-a-string-with-words-as-delimiters/m-p/539110#M148477</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-02-27T20:13:41Z</dc:date>
    </item>
  </channel>
</rss>

