<?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: Findw error with macro variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552237#M9152</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and gave the drugs output into a table. Below are 4 of the drugs listed from the top.&lt;/P&gt;
&lt;P&gt;1-(3-CHLOROPHENYL)PIPERAZINE&lt;BR /&gt;1-(5-METHOXY-1H-INDOL-3-YL)-2-PROPANAMINE&lt;BR /&gt;10-HYDROXYCARBAZEPINE&lt;BR /&gt;10-OH CARBAZEPINE&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These drugs are upper case. Your original code tested if lowcase(var1)&amp;nbsp;&lt;EM&gt;etc.&lt;/EM&gt; contains these drugs, and you have a case mismatch, you will never get "Yes" until you fix that.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Apr 2019 18:23:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-04-18T18:23:51Z</dc:date>
    <item>
      <title>Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552213#M9140</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use FINDW to find a list of words in string variables. Since I have a long list of words that were originally taken from Excel, I put them all into a macro variable. So far I have the syntax below, but each time I run it, I get an error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a feeling it has to do with the fact some of the words in my list have spaces, parentheses and dashes, but I'm not sure how to account for that in my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set data;
	if findw(lowcase(var1),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var2),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var3),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var4),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var5),&amp;amp;alldrugs, '|','I S') &amp;gt;0 	
	then drug='Yes' ;
	else drug='No'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28803i9783D2D7358761E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552213#M9140</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T18:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552221#M9142</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set data;
	if findw(lowcase(var1),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var2),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var3),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var4),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var5),&amp;amp;alldrugs, '|','I S') &amp;gt;0 /*or	this is the error*/
	then drug='Yes' ;
	else drug='No'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;or &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; drug&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Yes'&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;; /*is&amp;nbsp;invalid*/&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 17:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552221#M9142</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-18T17:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552223#M9144</link>
      <description>&lt;P&gt;Sorry, that's a mistake in the example. In the original code there isn't an or at the end. I've corrected the question.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552223#M9144</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T18:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552224#M9145</link>
      <description>&lt;P&gt;Can you show us a portion of &amp;amp;alldrugs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One correction is that &amp;amp;alldrugs must be in double quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if findw(lowcase(var1),"&amp;amp;alldrugs", '|','I S') &amp;gt;0 or &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;etc.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not it, then please paste the entire SAS log, including the code and the error message (not just the error message) as text and not as a screen capture, by clicking on the {i} icon and pasting the text into the window that appears. &lt;STRONG&gt;Do not paste the text into your message any other way.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552224#M9145</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T18:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552228#M9148</link>
      <description>&lt;P&gt;Good point! I forgot to add those in. It removes the error message, but I still end up with no observations for drug='Yes' when there should be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of the &amp;amp;alldrugs variable, it was created with the following syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select drug_name into: alldrugs separated by ' '
from druglist;
quit;
%put &amp;amp;alldrugs;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and gave the drugs output into a table. Below are 4 of the drugs listed from the top.&lt;/P&gt;&lt;P&gt;1-(3-CHLOROPHENYL)PIPERAZINE&lt;BR /&gt;1-(5-METHOXY-1H-INDOL-3-YL)-2-PROPANAMINE&lt;BR /&gt;10-HYDROXYCARBAZEPINE&lt;BR /&gt;10-OH CARBAZEPINE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also should mention, some of the drugs have comma's so they are written as 1,3-dimethoxy. Which is why I have the data as pipe delimited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552228#M9148</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T18:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552236#M9151</link>
      <description>&lt;P&gt;Are expecting one value of VAR1 to have ALL of those drug names IN THAT EXACT ORDER?&lt;/P&gt;
&lt;P&gt;Or did you want to test if the value of VAR1 is in that list of drug names?&lt;/P&gt;
&lt;P&gt;Did you mean:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;findw("&amp;amp;alldrug",var1,....)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good point! I forgot to add those in. It removes the error message, but I still end up with no observations for drug='Yes' when there should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of the &amp;amp;alldrugs variable, it was created with the following syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select drug_name into: alldrugs separated by ' '
from druglist;
quit;
%put &amp;amp;alldrugs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and gave the drugs output into a table. Below are 4 of the drugs listed from the top.&lt;/P&gt;
&lt;P&gt;1-(3-CHLOROPHENYL)PIPERAZINE&lt;BR /&gt;1-(5-METHOXY-1H-INDOL-3-YL)-2-PROPANAMINE&lt;BR /&gt;10-HYDROXYCARBAZEPINE&lt;BR /&gt;10-OH CARBAZEPINE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552236#M9151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-18T18:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552237#M9152</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and gave the drugs output into a table. Below are 4 of the drugs listed from the top.&lt;/P&gt;
&lt;P&gt;1-(3-CHLOROPHENYL)PIPERAZINE&lt;BR /&gt;1-(5-METHOXY-1H-INDOL-3-YL)-2-PROPANAMINE&lt;BR /&gt;10-HYDROXYCARBAZEPINE&lt;BR /&gt;10-OH CARBAZEPINE&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These drugs are upper case. Your original code tested if lowcase(var1)&amp;nbsp;&lt;EM&gt;etc.&lt;/EM&gt; contains these drugs, and you have a case mismatch, you will never get "Yes" until you fix that.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552237#M9152</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T18:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552241#M9153</link>
      <description>&lt;P&gt;I tried changing that to make both lower case using the two following forms, but both don't seem to work.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set data;
	if findw(lowcase(var1),lowcase("&amp;amp;alldrugs"),' ', 'I S') &amp;gt;0 
then drug= 'Yes'; 
else drug='No'; 
run;

data test;
set data;
	if findw(lowcase(var1),compress(lowcase("&amp;amp;alldrugs")),' ', 'I S') &amp;gt;0 
then drug= 'Yes'; 
else drug='No'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552241#M9153</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T18:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552248#M9154</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to use FINDW to find a list of words in string variables. Since I have a long list of words that were originally taken from Excel, I put them all into a macro variable. So far I have the syntax below, but each time I run it, I get an error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a feeling it has to do with the fact some of the words in my list have spaces, parentheses and dashes, but I'm not sure how to account for that in my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set data;
	if findw(lowcase(var1),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var2),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var3),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var4),&amp;amp;alldrugs, '|','I S') &amp;gt;0 or 
	   findw(lowcase(var5),&amp;amp;alldrugs, '|','I S') &amp;gt;0 	
	then drug='Yes' ;
	else drug='No'; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28803i9783D2D7358761E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And your example data containing VAR1, Var2, Var3 etc is where?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;And you should provide the actual value of that macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect the basic problem is order of the variables. The first argument of FINDW is the value to search in and the second parameter is what to search for. Does that sound like what you are doing?&lt;/P&gt;
&lt;P&gt;See this small example:&lt;/P&gt;
&lt;PRE&gt;data example;
   longstring= "this is a string with several words";
   x ="string with";
   y= findw(longstring,x);
   z= findw(x,longstr);
run;&lt;/PRE&gt;
&lt;P&gt;Your FINDW&amp;nbsp;code I think looks more like the Z version above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552248#M9154</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-18T18:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552250#M9155</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;said, we need to see your data now — a portion of it where you expect to get a match with one of the drugs in &amp;amp;alldrugs.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 18:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552250#M9155</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T18:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552278#M9159</link>
      <description>&lt;P&gt;Due to the sensitivity of this data I cannot provide further info. Instead, I will provide an example to better explain my question. Lets say I have an Excel spreadsheet with a list of fake flowers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Flowers:&lt;/P&gt;&lt;P&gt;1. Orchids&lt;/P&gt;&lt;P&gt;2. Lilies&lt;/P&gt;&lt;P&gt;3. Roses&lt;/P&gt;&lt;P&gt;4. 1,4,5-Daisy&lt;/P&gt;&lt;P&gt;5. Dahlia&lt;/P&gt;&lt;P&gt;6. 3,4-Lilac(2-Lilies)Daisy&lt;/P&gt;&lt;P&gt;7. Common lilac&lt;/P&gt;&lt;P&gt;8. False goats beard&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say these flowers were placed into &amp;amp;alldrugs. Now in my data I have an observation with the following report under var1:&lt;/P&gt;&lt;P&gt;"The house was surrounded with various objects. Some objects being boxes, shoes, and roses."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want sas to read through that statement and see if the keywords from &amp;amp;alldrugs are mentioned in that statement. If not then to say "No".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My syntax was originally this, but it takes too long to run and I would like it to be more efficient by using the syntax I provided in the original question.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	drug=1;
	i=1;
	do while ((scan("&amp;amp;alldrugs",i,"|") ne '') and drug&amp;gt;0);		
	  i+1;																/*Number of the drug found on the keyword list -1 */
	  drug_word=scan("&amp;amp;alldrugs",i-1,"|");							
	  indx_drug1=findw(lowcase(var1),compress(lowcase(drug_word)));
	  indx_drug2=findw(lowcase(var2),compress(lowcase(drug_word)));
	  indx_drug3=findw(lowcase(var3),compress(lowcase(drug_word)));
	  indx_drug4=findw(lowcase(var4),compress(lowcase(drug_word)));
	  indx_drug5=findw(lowcase(var5),compress(lowcase(drugd_word)));
	  indx_drug6=findw(lowcase(var6),compress(lowcase(drug_word)));
	  indx_drug7=findw(lowcase(var7),compress(lowcase(drug_word)));

if indx_drug1&amp;gt;0 or indx_drug2&amp;gt;0 or .... indx_drug7&amp;gt;0 then drug=1;
else drug=drug+1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 19:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552278#M9159</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T19:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552287#M9161</link>
      <description>&lt;P&gt;It's fine if you give us a made up example, because real data is sensitive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alldrugs=orchids|lillies|roses|daisy;

data a;
	var1="The house was surrounded with various objects. Some objects being boxes, shoes, and roses.";
	i=1;
	do while (scan("&amp;amp;alldrugs",i,"|") ne '');		
	  i+1;																/*Number of the drug found on the keyword list -1 */
	  drug_word=scan("&amp;amp;alldrugs",i-1,"|");							
	  indx_drug1=findw(lowcase(var1),compress(lowcase(drug_word)));
	  output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 19:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552287#M9161</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T19:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552294#M9163</link>
      <description>&lt;P&gt;Do you know if there's a way to run that without having to write everything out? The keylist has about 200 words, and the variables have around 50k observations with a different response on each.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you! I really appreciate all the input that's been provided.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 19:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552294#M9163</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T19:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552307#M9165</link>
      <description>&lt;P&gt;Is this what you mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	array index_drug $ index_drug1-index_drug4;
	array drug_word $ drug_word1-drug_word4;
	var1="The house was surrounded with various objects. Some objects being boxes, shoes, and roses.";
	do i=1 to countw("&amp;amp;alldrugs",'|');
	  drug_word(i)=scan("&amp;amp;alldrugs",i,"|");							
	  index_drug(i)=findw(lowcase(var1),compress(lowcase(drug_word(i))));
	end;
	if sum(of index_drug:)&amp;gt;0 then index=1; else index=0;
	drop var1 i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can drop additional variables from the data set if desired.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 19:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552307#M9165</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T19:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552315#M9167</link>
      <description>&lt;P&gt;or this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alldrugs=orchids|lillies|roses|daisy;
%let ndrugs=%sysfunc(countw(&amp;amp;alldrugs,|));
data customer;
	input var1 $100.;
	cards;
The house was surrounded with various objects. Some objects being boxes, shoes, and roses.
The house was surrounded with various objects. Some objects being boxes, lillies, and frogs.
The house was surrounded with various objects. Some objects being boxes, oranges and frogs.
;
data a;
	array index_drug $ index_drug1-index_drug4;
	array drug_word $ drug_word1-drug_word&amp;amp;ndrugs;
	set customer;
	cust_no=_n_;
	do i=1 to &amp;amp;ndrugs;
	  drug_word(i)=scan("&amp;amp;alldrugs",i,"|");							
	  index_drug(i)=findw(lowcase(var1),compress(lowcase(drug_word(i))));
	end;
	if sum(of index_drug:)&amp;gt;0 then index=1; else index=0;
	drop var1 i drug_word:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 19:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552315#M9167</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T19:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552327#M9171</link>
      <description>&lt;P&gt;Also, I was wrong earlier about the case of the text. Your FINDW command uses the modifier 'i' which then ignores the case of the text when finding matches.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 20:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552327#M9171</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-18T20:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552372#M9180</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Due to the sensitivity of this data I cannot provide further info. Instead, I will provide an example to better explain my question. Lets say I have an Excel spreadsheet with a list of fake flowers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Flowers:&lt;/P&gt;
&lt;P&gt;1. Orchids&lt;/P&gt;
&lt;P&gt;2. Lilies&lt;/P&gt;
&lt;P&gt;3. Roses&lt;/P&gt;
&lt;P&gt;4. 1,4,5-Daisy&lt;/P&gt;
&lt;P&gt;5. Dahlia&lt;/P&gt;
&lt;P&gt;6. 3,4-Lilac(2-Lilies)Daisy&lt;/P&gt;
&lt;P&gt;7. Common lilac&lt;/P&gt;
&lt;P&gt;8. False goats beard&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say these flowers were placed into &amp;amp;alldrugs. Now in my data I have an observation with the following report under var1:&lt;/P&gt;
&lt;P&gt;"The house was surrounded with various objects. Some objects being boxes, shoes, and roses."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want sas to read through that statement and see if the keywords from &amp;amp;alldrugs are mentioned in that statement. If not then to say "No".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My syntax was originally this, but it takes too long to run and I would like it to be more efficient by using the syntax I provided in the original question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	drug=1;
	i=1;
	do while ((scan("&amp;amp;alldrugs",i,"|") ne '') and drug&amp;gt;0);		
	  i+1;																/*Number of the drug found on the keyword list -1 */
	  drug_word=scan("&amp;amp;alldrugs",i-1,"|");							
	  indx_drug1=findw(lowcase(var1),compress(lowcase(drug_word)));
	  indx_drug2=findw(lowcase(var2),compress(lowcase(drug_word)));
	  indx_drug3=findw(lowcase(var3),compress(lowcase(drug_word)));
	  indx_drug4=findw(lowcase(var4),compress(lowcase(drug_word)));
	  indx_drug5=findw(lowcase(var5),compress(lowcase(drugd_word)));
	  indx_drug6=findw(lowcase(var6),compress(lowcase(drug_word)));
	  indx_drug7=findw(lowcase(var7),compress(lowcase(drug_word)));

if indx_drug1&amp;gt;0 or indx_drug2&amp;gt;0 or .... indx_drug7&amp;gt;0 then drug=1;
else drug=drug+1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you actually need all of the different index variables for other work or do you just want the any are found? It isn't quite clear whether you need to count the number of drugs that appear in all of the phrases, one phrase or what. Which is why we ask for a concrete example. The values do not have to match your data as long as the behavior of the need can be demonstrated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 22:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552372#M9180</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-18T22:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552373#M9181</link>
      <description>&lt;P&gt;This is a first step to a long process. As you said, my intent is to get the cases where at least one word from the keylist appeared under the variables for each observation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is quite complex which is why it has been difficult to provide a concise example. I am looking at a total of 12 variables that each contain string variables (in the example they are vars1-7). The process in my original syntax was to find the words from the keylist and see if they are present in the responses for each observation. The word needs to match exactly as written in the keylist. Not every case will have a the keywords, and therefore will not be cases.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 23:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552373#M9181</guid>
      <dc:creator>JoanneR</dc:creator>
      <dc:date>2019-04-18T23:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552374#M9182</link>
      <description>&lt;P&gt;See if this also helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select quote(strip(name)) into : namelist separated by ','
   from sashelp.class
   ;
quit;
%let namecount = &amp;amp;sqlobs.;

%put Names are &amp;amp;namelist. count is &amp;amp;namecount.;

data example;
   infile datalines truncover;
   informat var1 var2 $35.;
   input var1 1-35
         /var2 1-35
   ;
datalines;
First var string with no name
and a second with no name
Example of one name 
that is John in two lines
And more names like Alice, Mary
and james
;
run;



data want;
   set example;
   array name{&amp;amp;namecount.} $20 _temporary_ (&amp;amp;namelist.);
   array v var1 var2;
   wordcount=0;
   do i= 1 to dim(name);
      do j=1 to dim(v);
         wordcount= wordcount+ (findw(v[j],strip(name[i]),' ','IPQRO')&amp;gt;0);
      end;
   end;
   drop i j;
run;&lt;/PRE&gt;
&lt;P&gt;I am still not sure if you need an over all count of the drugs in all the phrases only, in each phrase, or some combination. This only does an over all count and only uses two variables to search as I am not going to spend a lot time making dummy data when I really don't know how well it might replicate your situation.&lt;/P&gt;
&lt;P&gt;I does use a data set value to populate the list.&lt;/P&gt;
&lt;P&gt;In your particular case you need to ensure that the length of the variable in the array name statement, the 20, is at least as long as the longest value in your word list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &amp;amp;sqlobs macro variable is an automatic count of the result from the last Proc SQL. It is also very likely to be resent so capture it into a known variable. The value is needed because you must specify the number of elements in the _temporary_ array. The SQL places quotes and commas so the single macro variable resolves properly for the _temporary_ array values.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 23:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552374#M9182</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-18T23:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Findw error with macro variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552486#M9197</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266130"&gt;@JoanneR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is a first step to a long process. As you said, my intent is to get the cases where at least one word from the keylist appeared under the variables for each observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is quite complex which is why it has been difficult to provide a concise example. I am looking at a total of 12 variables that each contain string variables (in the example they are vars1-7). The process in my original syntax was to find the words from the keylist and see if they are present in the responses for each observation. The word needs to match exactly as written in the keylist. Not every case will have a the keywords, and therefore will not be cases.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you need to know which variable found contained a key word then you could add and array to my example that has a Found value for each of the VAR variables. Instead of the single accumulator you would need to set the accumulator between the I and J loops to reset and then save after the end of the J loop if you need a NUMBER of matches, You can also use the I value when the count increments to keep identifiers of the found key words as that seems like it may be of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really providing some sort of example input data and the desired result for that is the way to ask questions. We are sort of wandering around with not knowing exactly the requirement such as :&lt;/P&gt;
&lt;P&gt;Any of the key words found in any of the variables&lt;/P&gt;
&lt;P&gt;How many of the key words found in any of the variables&lt;/P&gt;
&lt;P&gt;Which of the key words found in any of the variables&lt;/P&gt;
&lt;P&gt;Any of the key&amp;nbsp; words found in each of the variables&lt;/P&gt;
&lt;P&gt;How many of the key&amp;nbsp; words found in each of the variables&lt;/P&gt;
&lt;P&gt;Which&amp;nbsp;of the key&amp;nbsp; words found in each of the variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This example creates a count per Var variable of the number of words matched and creates a delimited list of the words found from the key word list. If your values might contain commas then use a different delimiter in the CATX function call that you do not have in our key words.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select quote(strip(name)) into : namelist separated by ','
   from sashelp.class
   ;
quit;
%let namecount = &amp;amp;sqlobs.;

%put Names are &amp;amp;namelist. count is &amp;amp;namecount.;

data example;
   infile datalines truncover;
   informat var1 var2 $35.;
   input var1 1-35
         /var2 1-35
   ;
datalines;
First var string with no name
and a second with no name
Example of one name 
that is John in two lines
And more names like Alice, Mary
and james
;
run;



data want;
   set example;
   array name{&amp;amp;namecount.} $20 _temporary_ (&amp;amp;namelist.);
   array v var1 var2;
   /* the 2 below matches the number of VAR variables*/
   /* fcount will have the number of found words per var*/
   array fcount (2);
   /* this will hold a list of the found words*/
   array fwords (2) $ 200;
   
   do i= 1 to dim(name);
      do j=1 to dim(v);
         t= (findw(v[j],strip(name[i]),' ','IPQRO')&amp;gt;0);
         fcount[j]= sum(fcount[j], t);
         if t then fwords[j]= catx(',',fwords[j],strip(name[i]));
      end;
   end;
   drop i j t;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Apr 2019 16:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Findw-error-with-macro-variable/m-p/552486#M9197</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-19T16:44:51Z</dc:date>
    </item>
  </channel>
</rss>

