<?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 words from a sentence into variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551698#M153310</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    infile cards dlm='+' dsd;
    format review_ID z4. review $80.;
    input review_ID review;
    cards;
0001+I am satisfied with the staff and also the restaurant
0002+The swimming pool, spa and bar are amazing
;
run;

data keywords;
input keyword $20.;
    cards;
staff
restaurant
swimming pool
spa
bar
;
run;


proc sql;
create table temp as
select review_id,keyword
 from have as a,keywords as b
  where find(review,strip(keyword),'i')
   order by review_id;
quit;
proc transpose data=temp out=want prefix=review;
by review_id;
var keyword;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Apr 2019 13:13:21 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-04-17T13:13:21Z</dc:date>
    <item>
      <title>How to split words from a sentence into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551628#M153280</link>
      <description>&lt;P&gt;I want to split a text variable into different new variables but only keeping words that I want as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original dataset:&lt;/P&gt;&lt;P&gt;review_ID&amp;nbsp; &amp;nbsp; review&lt;/P&gt;&lt;P&gt;0001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I am satisfied with the staff and also the restaurant&lt;/P&gt;&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The swimming pool, spa and bar are amazing&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keywords that I want to keep:&lt;/P&gt;&lt;P&gt;staff&lt;/P&gt;&lt;P&gt;restaurant&lt;/P&gt;&lt;P&gt;swimming pool&lt;/P&gt;&lt;P&gt;spa&lt;/P&gt;&lt;P&gt;bar&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset that I want:&lt;/P&gt;&lt;P&gt;review_ID&amp;nbsp; &amp;nbsp; review1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; review2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; review3&lt;/P&gt;&lt;P&gt;0001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;staff&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;restaurant&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;/P&gt;&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;swimming pool&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;spa&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bar&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me out please?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 08:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551628#M153280</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2019-04-17T08:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to split words from a sentence into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551631#M153283</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further processing and since you don't know in advance how many keywords you will find for each ID, it is better to use a vertical data storage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    infile cards dlm='+' dsd;
    format review_ID z4. review $80.;
    input review_ID review;
    cards;
0001+I am satisfied with the staff and also the restaurant
0002+The swimming pool, spa and bar are amazing
;
run;

data keywords;
    length keyword $20.;
    input keyword;
    cards;
staff
restaurant
swimming pool
spa
bar
;
run;

proc sql noprint;
    SELECT count(keyword) INTO :nk
    FROM keywords;
quit;

data want (rename=(_review=review));
    set have;
    length _review $20.;

    array kw(&amp;amp;nk.) $20.;
    retain kw:;

    if _N_=1 then do i=1 to dim(kw);
        set keywords;
        kw(i)=keyword;
    end;

    do i=1 to dim(kw);
        if findw(review,strip(kw(i))) then do;
            _review=kw(i);
            output;
        end;
    end;

    if _review=" " then output;

    keep review_ID _review;

run;

data _NULL_;
    set want;
    by review_ID;

    if first.review_ID then put review_ID@;

    if last.review_ID then put review;
    else put review@;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2019 09:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551631#M153283</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-04-17T09:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to split words from a sentence into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551698#M153310</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    infile cards dlm='+' dsd;
    format review_ID z4. review $80.;
    input review_ID review;
    cards;
0001+I am satisfied with the staff and also the restaurant
0002+The swimming pool, spa and bar are amazing
;
run;

data keywords;
input keyword $20.;
    cards;
staff
restaurant
swimming pool
spa
bar
;
run;


proc sql;
create table temp as
select review_id,keyword
 from have as a,keywords as b
  where find(review,strip(keyword),'i')
   order by review_id;
quit;
proc transpose data=temp out=want prefix=review;
by review_id;
var keyword;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2019 13:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551698#M153310</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-17T13:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to split words from a sentence into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551992#M153439</link>
      <description>Thanks!!! Your method can do exactly what I want!</description>
      <pubDate>Thu, 18 Apr 2019 04:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551992#M153439</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2019-04-18T04:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to split words from a sentence into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551993#M153440</link>
      <description>Thanks!!! You coding works!</description>
      <pubDate>Thu, 18 Apr 2019 04:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-words-from-a-sentence-into-variables/m-p/551993#M153440</guid>
      <dc:creator>Jonathanzz</dc:creator>
      <dc:date>2019-04-18T04:44:51Z</dc:date>
    </item>
  </channel>
</rss>

