<?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: How to split a string when AND or OR is found? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666881#M199610</link>
    <description>&lt;P&gt;You gave only one example and did not relate to the example I have posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your specific example you can use next code,&amp;nbsp;though it's not a complete, because&lt;/P&gt;
&lt;P&gt;you will get a bad result for the 2nd example. Check output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   infile cards truncover;
   input hobbies $char50. ;
cards;
Reading and Singing
I like to read books and to draw pictures
;
run;
data want;
 set test;
    do i=1 to countw(hobbies);
       if scan(lowcase(hobbies),i) in ('and', 'or') then do;
          hobby1 = scan(hobbies, i-1);
          hobby2 = scan(hobbies, i+1);
          output;
       end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get a better code you need to post more examples with the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming hobbies are usually verbs, it may be more difficult to decide by a program which word is a verb.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jul 2020 19:47:03 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-07-03T19:47:03Z</dc:date>
    <item>
      <title>How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666870#M199604</link>
      <description>&lt;P&gt;Sample string-&lt;/P&gt;&lt;P&gt;Hobbies= Reading and singing.&lt;/P&gt;&lt;P&gt;How to store Reading and singing in two separate variables such as Hobby 1 and Hobby 2?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hobby1= Reading&lt;/P&gt;&lt;P&gt;Hobby2= Singing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 18:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666870#M199604</guid>
      <dc:creator>inavjots</dc:creator>
      <dc:date>2020-07-03T18:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666874#M199605</link>
      <description>&lt;P&gt;Are you looking for verbs?&lt;/P&gt;
&lt;P&gt;What would you subset into verbs having a text like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; a = "I like to read books and to draw pictures" - ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should post more examples and try to define the rules of words to look for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 18:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666874#M199605</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-03T18:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666877#M199606</link>
      <description>The question has been updated. Please take a look now. I hope it is understandable now.</description>
      <pubDate>Fri, 03 Jul 2020 18:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666877#M199606</guid>
      <dc:creator>inavjots</dc:creator>
      <dc:date>2020-07-03T18:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666878#M199607</link>
      <description>You can use SCAN() and FINDW()&lt;BR /&gt;&lt;BR /&gt;Use FINDW() to see if you have an AND/OR and then if you do, use SCAN() to portion them out. Or use SCAN to loop through the words and drop any and/or's.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Jul 2020 19:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666878#M199607</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-03T19:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666879#M199608</link>
      <description>Thank you for your reply, Could you please explain it with an example? I am not familiar with FINDW().</description>
      <pubDate>Fri, 03 Jul 2020 19:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666879#M199608</guid>
      <dc:creator>inavjots</dc:creator>
      <dc:date>2020-07-03T19:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666880#M199609</link>
      <description>This is the closest example I have. You can add conditions to it. &lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/bed5ea2c12903b38fdcf19f3f1f1aae9" target="_blank"&gt;https://gist.github.com/statgeek/bed5ea2c12903b38fdcf19f3f1f1aae9&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If you need further assistance please show what you've tried and what issues you're having.</description>
      <pubDate>Fri, 03 Jul 2020 19:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666880#M199609</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-03T19:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666881#M199610</link>
      <description>&lt;P&gt;You gave only one example and did not relate to the example I have posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your specific example you can use next code,&amp;nbsp;though it's not a complete, because&lt;/P&gt;
&lt;P&gt;you will get a bad result for the 2nd example. Check output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   infile cards truncover;
   input hobbies $char50. ;
cards;
Reading and Singing
I like to read books and to draw pictures
;
run;
data want;
 set test;
    do i=1 to countw(hobbies);
       if scan(lowcase(hobbies),i) in ('and', 'or') then do;
          hobby1 = scan(hobbies, i-1);
          hobby2 = scan(hobbies, i+1);
          output;
       end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get a better code you need to post more examples with the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming hobbies are usually verbs, it may be more difficult to decide by a program which word is a verb.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 19:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666881#M199610</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-03T19:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string when AND or OR is found?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666883#M199612</link>
      <description>&lt;P&gt;This is perfect. Much obliged.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 20:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-string-when-AND-or-OR-is-found/m-p/666883#M199612</guid>
      <dc:creator>inavjots</dc:creator>
      <dc:date>2020-07-03T20:07:09Z</dc:date>
    </item>
  </channel>
</rss>

