<?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 split one string into multiple rows for each phrase, without a delimiter for each phrase in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385611#M92265</link>
    <description>&lt;P&gt;I have a data set that looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=','; 
input IDnumber String $50.; 
datalines;           
2477,Cat Dog A blue car
2431,Cat Fish Yelllow Submarine 
;             
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to extract each data item from the string to one row so that i get this:&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 want;
infile datalines delimiter=','; 
input IDnumber String $50.; 
datalines;           
2477,Cat
2477,Dog
2477,A blue car
2431,Cat
2431,Fish 
2431,Yelllow Submarine 
;             
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The text will sometimes be split by a single word, other times several words constitute one phrase, and one phrase can sometimes start with a capital letter followed by a small letter in the next word, but othertimes it has capital letters in both words of one phrase, so I cannot use regexp or the like to do a sort of conditional do loop or array. I basically need to hardcode it so something like this, but cant quite wrap my head around the right syntax:&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 try;
set have;
do ... ;
if index(String,'Cat') &amp;gt; 0 then output Phrase = 'Cat' ;
if index(String,'Dog') &amp;gt; 0 then output Phrase = 'Dog' ;
if index(String,'A blue car') &amp;gt; 0 then output Phrase = 'A blue car' ;
if index(String,'Fish') &amp;gt; 0 then output Phrase = 'Fish' ;
if index(String,'Yellow submarine') &amp;gt; 0 then output Phrase = 'Yellow submarine' ;
;
end;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Aug 2017 09:25:10 GMT</pubDate>
    <dc:creator>Ullsokk</dc:creator>
    <dc:date>2017-08-04T09:25:10Z</dc:date>
    <item>
      <title>split one string into multiple rows for each phrase, without a delimiter for each phrase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385611#M92265</link>
      <description>&lt;P&gt;I have a data set that looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=','; 
input IDnumber String $50.; 
datalines;           
2477,Cat Dog A blue car
2431,Cat Fish Yelllow Submarine 
;             
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to extract each data item from the string to one row so that i get this:&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 want;
infile datalines delimiter=','; 
input IDnumber String $50.; 
datalines;           
2477,Cat
2477,Dog
2477,A blue car
2431,Cat
2431,Fish 
2431,Yelllow Submarine 
;             
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The text will sometimes be split by a single word, other times several words constitute one phrase, and one phrase can sometimes start with a capital letter followed by a small letter in the next word, but othertimes it has capital letters in both words of one phrase, so I cannot use regexp or the like to do a sort of conditional do loop or array. I basically need to hardcode it so something like this, but cant quite wrap my head around the right syntax:&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 try;
set have;
do ... ;
if index(String,'Cat') &amp;gt; 0 then output Phrase = 'Cat' ;
if index(String,'Dog') &amp;gt; 0 then output Phrase = 'Dog' ;
if index(String,'A blue car') &amp;gt; 0 then output Phrase = 'A blue car' ;
if index(String,'Fish') &amp;gt; 0 then output Phrase = 'Fish' ;
if index(String,'Yellow submarine') &amp;gt; 0 then output Phrase = 'Yellow submarine' ;
;
end;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 09:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385611#M92265</guid>
      <dc:creator>Ullsokk</dc:creator>
      <dc:date>2017-08-04T09:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: split one string into multiple rows for each phrase, without a delimiter for each phrase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385617#M92267</link>
      <description>&lt;P&gt;Sorry, I don't see logically how I would know that "A blue car" is a separate from another string. &amp;nbsp;I mean its simple enough to split by word:&lt;/P&gt;
&lt;PRE&gt;data want;
  length word $200;
  set have;
  do i=1 to countw(string," ");
    word=scan(string,i," ");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;But I don't see anything logical about how to get Yellow Submarine or A blue car?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 09:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385617#M92267</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-08-04T09:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: split one string into multiple rows for each phrase, without a delimiter for each phrase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385618#M92268</link>
      <description>&lt;P&gt;An interesting issue. You don't need a loop, just and do...end and swap output-statement and assignment.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data try;
set have;

if index(String,'Cat') &amp;gt; 0 then do; Phrase = 'Cat' ; output; end;
...
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2017 09:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-one-string-into-multiple-rows-for-each-phrase-without-a/m-p/385618#M92268</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-08-04T09:45:03Z</dc:date>
    </item>
  </channel>
</rss>

