<?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 do I read a single word from a wordlist? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277933#M55873</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.insurance;
infile datalines dsd;
input word:$25. category: $11.;
datalines;
inferno,earthquake
flames,earthquake
burning,earthquake
combustion,earthquake
burn,earthquake
shaking,earthquake
shake,earthquake
vibrate,earthquake
tremble,earthquake
magnitude,earthquake
epicenter,earthquake
fire,fire
blaze,fire
conflagration,fire
inferno,fire
firestorm,fire
burning,fire
combustion,fire
ignite,fire
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this case the wordlist for fire would look something like: fire, inferno, combustion, burning, firestorm.&lt;/P&gt;&lt;P&gt;I don't just want the observations in the fire category, but also the ones with the same words&amp;nbsp; in the other categories.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2016 15:23:30 GMT</pubDate>
    <dc:creator>myname</dc:creator>
    <dc:date>2016-06-16T15:23:30Z</dc:date>
    <item>
      <title>How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277917#M55869</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently facing the problem of subsetting a dataset by words listed in a wordlist.&lt;/P&gt;&lt;P&gt;The dataset I have is quite large and includes the variables word and collection. I want to subset this dataset based on the observations in the variable word. For this I have several wordlists that include up to 60 words. As I do not want to write them all in a data step (especially as the word lists may change later on) I wrote myself a macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS MPRINT;
%macro subset(cat);
proc sql ;
select distinct word 
into :word_list_&amp;amp;cat separated by " "
from work.&amp;amp;cat;
quit;

data work.subset_&amp;amp;cat;
set work.insurance;
%do i=1 %to 50;
%if word="qscan(&amp;amp;word_list_&amp;amp;cat,&amp;amp;i)" %then output;
%end;
run;
%mend subset;


%subset(fire)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am quite new to working with macros, so this does&amp;nbsp;not work, obviously.&amp;nbsp;The error I get is&lt;/P&gt;&lt;P&gt;"WARNING: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation&lt;/P&gt;&lt;P&gt;marks."&lt;/P&gt;&lt;P&gt;which I understand, SAS obviously reads the whole word list into the quotes, but I only want the first, second, third, and so on at one time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be very grateful if someone could help me out with this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 14:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277917#M55869</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-16T14:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277924#M55870</link>
      <description>&lt;P&gt;Please post test data (as a datastep), it is very hard to visualise data we can't see. &amp;nbsp;At a guess:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set catds;
  call execute(cats('data want_',word,'; set work.insuarance (where=(word="',word,'")); run;'));
run;&lt;/PRE&gt;
&lt;P&gt;This will &amp;nbsp;create a datastep for each observation in catds which has a where for the word on that observation. &amp;nbsp;Quite simple. &amp;nbsp;however I would also advise against creating lots of datasets - it really is not a good way of working. &amp;nbsp;SAS is setup to use by group processing, so create a variable in your data whith this grouping, and then use that as a by group - far simpler coding.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 15:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277924#M55870</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-16T15:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277925#M55871</link>
      <description>&lt;P&gt;This would be simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS MPRINT;
%macro subset(cat);

proc sql;
create table work.subset_&amp;amp;cat as
select * 
from  work.insurance
where word in (select word from work.&amp;amp;cat);
quit;

%mend subset;

%subset(fire)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 15:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277925#M55871</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-16T15:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277933#M55873</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.insurance;
infile datalines dsd;
input word:$25. category: $11.;
datalines;
inferno,earthquake
flames,earthquake
burning,earthquake
combustion,earthquake
burn,earthquake
shaking,earthquake
shake,earthquake
vibrate,earthquake
tremble,earthquake
magnitude,earthquake
epicenter,earthquake
fire,fire
blaze,fire
conflagration,fire
inferno,fire
firestorm,fire
burning,fire
combustion,fire
ignite,fire
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this case the wordlist for fire would look something like: fire, inferno, combustion, burning, firestorm.&lt;/P&gt;&lt;P&gt;I don't just want the observations in the fire category, but also the ones with the same words&amp;nbsp; in the other categories.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 15:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277933#M55873</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-16T15:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277944#M55875</link>
      <description>&lt;P&gt;Ok, little change then:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set insurance;
  by category;
  if first.category then call execute(cats('data want_',category,'; set have where=(word in ("',word,'"'));
  call execute(cats(',"',word,'"'));
  if last.category then call execute(')); run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will create one datastep per category with a where clause with each of the words in that category.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 15:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/277944#M55875</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-16T15:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278127#M55933</link>
      <description>I really tried to make that code work because I think it will help me a lot in further problems, but I couldn't.&lt;BR /&gt;SAS kept on giving out errors because of the comma in the second execute statement. I tried exchanging it with = or OR, both of which did not have the result I wanted. Is there another way to make it a list and not a condition?</description>
      <pubDate>Fri, 17 Jun 2016 07:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278127#M55933</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-17T07:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278137#M55936</link>
      <description>&lt;P&gt;Was a typo in there thats why, the where needs brackets around it. &amp;nbsp;Basically call execute is generating a string - this string is being sent to the compliler which tries to read it as code, just like the code you submitted. &amp;nbsp;So the text generated has to be valida SAS syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data insurance;
  word="abc"; category="cat1"; output;
  word="def"; category="cat1"; output;
run;
data have;
  word="abc"; output;
run;

data _null_;
  set insurance;
  by category;
  if first.category then call execute(cats('data want_',category,'; set have (where=(word in ("',word,'"'));
  else call execute(cats(',"',word,'"'));
  if last.category then call execute('))); run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2016 09:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278137#M55936</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-17T09:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I read a single word from a wordlist?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278190#M55951</link>
      <description>Thank you so much, this works perfectly!</description>
      <pubDate>Fri, 17 Jun 2016 13:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-read-a-single-word-from-a-wordlist/m-p/278190#M55951</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-06-17T13:37:06Z</dc:date>
    </item>
  </channel>
</rss>

