<?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: Splitting a string into multiple rows where delimiter is a phrase, not a single character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436233#M282155</link>
    <description>&lt;P&gt;If you are reading from the html file directly, you can use the DLMSTR= option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile datalines dlmstr='&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';&lt;/P&gt;
&lt;P&gt;length text $ 250;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 1000 until (text=' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input text @;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if text &amp;gt; ' ' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;.........use the wide data line here ...............................&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, however, that the delimiting string would NOT become part of the value of TEXT.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2018 14:31:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-12T14:31:48Z</dc:date>
    <item>
      <title>Splitting a string into multiple rows where delimiter is a phrase, not a single character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436208#M282153</link>
      <description>&lt;P&gt;I have a data set from a html where all the data is stored in one sting:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
text = '&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A._Buddes_Vei/"title="A.BuddesVeiiStavanger"&amp;gt;A.BuddesVei&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A.b.c.gata/"title="A.b.c.gataiStavanger"&amp;gt;A.b.c.gata&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/Abelstrappa/"title="AbelstrappaiStavanger"&amp;gt;Abelstrappa&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to split this by each occurence of the string '&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;'. I want to try something like this, but where I can choose&amp;nbsp;this&amp;nbsp;"phrase" as the delimiter, not each individual character. The code below does not work,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data try (keep=new);
 set have ; 
 do i=1 by 1 while(scan(text,i,'&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;') ^=' '); 
new=scan(text,i,'&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;'); 
output; 
end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I want is this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input text $250.;
datalines;
&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A._Buddes_Vei/"title="A.BuddesVeiiStavanger"&amp;gt;A.BuddesVei&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; 
&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A.b.c.gata/"title="A.b.c.gataiStavanger"&amp;gt;A.b.c.gata&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; 
&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/Abelstrappa/"title="AbelstrappaiStavanger"&amp;gt;Abelstrappa&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 13:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436208#M282153</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2018-02-12T13:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string into multiple rows where delimiter is a phrase, not a single character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436223#M282154</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;%let dlm=&amp;lt;/li&amp;gt;;

data have;
 text='&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A._Buddes_Vei/"title="A.BuddesVeiiStavanger"&amp;gt;A.BuddesVei&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A.b.c.gata/"title="A.b.c.gataiStavanger"&amp;gt;A.b.c.gata&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/Abelstrappa/"title="AbelstrappaiStavanger"&amp;gt;Abelstrappa&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';
run;

data want /*(keep=res)*/;
  set have;
  length res $2000;
  do while(lengthn(text) &amp;gt; 0);
    res=substr(text,1,index(text,"&amp;amp;dlm.")+(lengthn("&amp;amp;dlm.")-1));
    output;
    text=substr(text,index(text,"&amp;amp;dlm.")+lengthn("&amp;amp;dlm."));
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2018 14:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436223#M282154</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-12T14:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string into multiple rows where delimiter is a phrase, not a single character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436233#M282155</link>
      <description>&lt;P&gt;If you are reading from the html file directly, you can use the DLMSTR= option on the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile datalines dlmstr='&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';&lt;/P&gt;
&lt;P&gt;length text $ 250;&lt;/P&gt;
&lt;P&gt;do _n_=1 to 1000 until (text=' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input text @;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if text &amp;gt; ' ' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;.........use the wide data line here ...............................&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, however, that the delimiting string would NOT become part of the value of TEXT.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 14:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436233#M282155</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-12T14:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string into multiple rows where delimiter is a phrase, not a single character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436252#M282156</link>
      <description>&lt;P&gt;one more way&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep = new);
	set have;
length val $350;
	IF _N_=1 THEN
		PATTERN=PRXPARSE ("/(.+?\&amp;lt;\/a\&amp;gt;\&amp;lt;\/li\&amp;gt;)/");
	retain pattern;
 start = 1;
 stop = length(text);
call prxnext(pattern,start,stop,text,position,length);
do while (position &amp;gt; 0);
new= substr(text,position,length);
call prxnext(pattern,start,stop,text,position,length);
output;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2018 15:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436252#M282156</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-02-12T15:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a string into multiple rows where delimiter is a phrase, not a single character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436649#M282157</link>
      <description>&lt;P&gt;How about this one ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
text = '&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A._Buddes_Vei/"title="A.BuddesVeiiStavanger"&amp;gt;A.BuddesVei&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/A.b.c.gata/"title="A.b.c.gataiStavanger"&amp;gt;A.b.c.gata&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;ahref="/Stavanger/Abelstrappa/"title="AbelstrappaiStavanger"&amp;gt;Abelstrappa&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;';
run;

data temp;
 set have;
 id+1;
 p=find(text,'&amp;lt;/li&amp;gt;');
 do while(p ne 0);
  output;
  p=find(text,'&amp;lt;/li&amp;gt;',p+1);
 end;
run;
data want;
 set temp;
 by id;
 lag=lag(p);
 dif=dif(p);
 if first.id then do;start=1;length=p+4;end;
  else do;start=lag+5;length=dif;end;
 str=substr(text,start,length);
keep text str;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Feb 2018 11:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-string-into-multiple-rows-where-delimiter-is-a/m-p/436649#M282157</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-13T11:29:44Z</dc:date>
    </item>
  </channel>
</rss>

