<?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: Find function with macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502713#M134236</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236159"&gt;@dera&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two data sets. The first one contains a list of patient with a description of their medical condition. The second one contains a list of code associated with key word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I removed spaces between words and put everything in capital letter to make data matching easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set "subject" contains description of medical condition looks like this (only one observation is shown but I have 20,000) :&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;CONCLUSION&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN&gt;SIGNOFARRHYTMIA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set "codes" contains codes associated with key word looks like this :&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;code&lt;/TD&gt;
&lt;TD&gt;yes_a&lt;/TD&gt;
&lt;TD&gt;yes_b&lt;/TD&gt;
&lt;TD&gt;no_a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1.5.1&lt;/TD&gt;
&lt;TD&gt;ARRHYTMIA&lt;/TD&gt;
&lt;TD&gt;ARHYTMIA&lt;/TD&gt;
&lt;TD&gt;NOSIGN&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000" size="4"&gt;I created a macro variable for every variable of the "codes" data set (see below)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
set codes;
	call symput("code",(code));
	call symput("yes_a",(yes_a));
	call symput("yes_b",(yes_b));
	call symput("no_a",(no_a));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, I told SAS "Look in the "conclusion" variable and if you can find the a match between the conclusion and the macro variable '&amp;amp;yes_a' then do a = 1" (see below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject_match; set subject;
if find (conclusion, '&amp;amp;yes_a') then a = 1;
if find (conclusion, '&amp;amp;no_a') then z = 0; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that this step doesn't work. I have no error code in the log but even if the words after in the string, "a" never equals to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Putting a bunch of values into macro variables is quite often the symptom of a not very well thought out process and often a misunderstanding of the macro processor. For example in this case the macro variable only contain the values from the last record of data set codes &lt;STRONG&gt;if that step executed at all. &lt;/STRONG&gt;The "end" has no do so that given data _null_ step won't execute at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second when wanting to use the value of a macro variable as text you use double quotes "&amp;nbsp; such as "&amp;amp;yes_a." not the single quotes. Other wise the value would not resolve at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many records are in your "codes" data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 14:29:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-10-09T14:29:22Z</dc:date>
    <item>
      <title>Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502706#M134230</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets. The first one contains a list of patient with a description of their medical condition. The second one contains a list of code associated with key word.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I removed spaces between words and put everything in capital letter to make data matching easier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set "subject" contains description of medical condition looks like this (only one observation is shown but I have 20,000) :&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;CONCLUSION&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class=""&gt;SIGNOFARRHYTMIA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set "codes" contains codes associated with key word looks like this :&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0" border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;code&lt;/TD&gt;&lt;TD&gt;yes_a&lt;/TD&gt;&lt;TD&gt;yes_b&lt;/TD&gt;&lt;TD&gt;no_a&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1.5.1&lt;/TD&gt;&lt;TD&gt;ARRHYTMIA&lt;/TD&gt;&lt;TD&gt;ARHYTMIA&lt;/TD&gt;&lt;TD&gt;NOSIGN&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a macro variable for every variable of the "codes" data set (see below)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
set codes;
	call symput("code",(code));
	call symput("yes_a",(yes_a));
	call symput("yes_b",(yes_b));
	call symput("no_a",(no_a));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After that, I told SAS "Look in the "conclusion" variable and if you can find the a match between the conclusion and the macro variable '&amp;amp;yes_a' then do a = 1" (see below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject_match; set subject;
if find (conclusion, '&amp;amp;yes_a') then a = 1;
if find (conclusion, '&amp;amp;no_a') then z = 0; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that this step doesn't work. I have no error code in the log but even if the words after in the string, "a" never equals to 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502706#M134230</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-10-09T14:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502710#M134233</link>
      <description>&lt;P&gt;After this step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
set codes;
	call symput("code",(code));
	call symput("yes_a",(yes_a));
	call symput("yes_b",(yes_b));
	call symput("no_a",(no_a));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;only the data from the &lt;EM&gt;last&lt;/EM&gt; observation in codes will be stored in the 4 macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502710#M134233</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-09T14:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502711#M134234</link>
      <description>&lt;P&gt;Well, first off macro variables need to be in double quotes to dereference:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;find&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;conclusion&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; "&lt;SPAN class="token string"&gt;&amp;amp;yes_a"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; a &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Secondly, always put the dot after macro variables, it is best practice as sometimes it will matter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, coding is more complicated than just finding strings in other strings, there could be any number of connotations.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502711#M134234</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-09T14:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502713#M134236</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236159"&gt;@dera&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two data sets. The first one contains a list of patient with a description of their medical condition. The second one contains a list of code associated with key word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I removed spaces between words and put everything in capital letter to make data matching easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set "subject" contains description of medical condition looks like this (only one observation is shown but I have 20,000) :&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;CONCLUSION&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN&gt;SIGNOFARRHYTMIA&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data set "codes" contains codes associated with key word looks like this :&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;code&lt;/TD&gt;
&lt;TD&gt;yes_a&lt;/TD&gt;
&lt;TD&gt;yes_b&lt;/TD&gt;
&lt;TD&gt;no_a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1.5.1&lt;/TD&gt;
&lt;TD&gt;ARRHYTMIA&lt;/TD&gt;
&lt;TD&gt;ARHYTMIA&lt;/TD&gt;
&lt;TD&gt;NOSIGN&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000" size="4"&gt;I created a macro variable for every variable of the "codes" data set (see below)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
set codes;
	call symput("code",(code));
	call symput("yes_a",(yes_a));
	call symput("yes_b",(yes_b));
	call symput("no_a",(no_a));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, I told SAS "Look in the "conclusion" variable and if you can find the a match between the conclusion and the macro variable '&amp;amp;yes_a' then do a = 1" (see below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject_match; set subject;
if find (conclusion, '&amp;amp;yes_a') then a = 1;
if find (conclusion, '&amp;amp;no_a') then z = 0; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that this step doesn't work. I have no error code in the log but even if the words after in the string, "a" never equals to 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Putting a bunch of values into macro variables is quite often the symptom of a not very well thought out process and often a misunderstanding of the macro processor. For example in this case the macro variable only contain the values from the last record of data set codes &lt;STRONG&gt;if that step executed at all. &lt;/STRONG&gt;The "end" has no do so that given data _null_ step won't execute at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second when wanting to use the value of a macro variable as text you use double quotes "&amp;nbsp; such as "&amp;amp;yes_a." not the single quotes. Other wise the value would not resolve at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many records are in your "codes" data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502713#M134236</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-09T14:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502718#M134239</link>
      <description>&lt;P&gt;about 350 codes&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502718#M134239</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-10-09T14:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502734#M134250</link>
      <description>I know that. I will add a "do loop" after for all the observation in the codes data set. But for now, I only test it with a single code and it does not work.&lt;BR /&gt;When I do %PUT yes_a = &amp;amp;yes_a, the log shows me that it succesfully find it.</description>
      <pubDate>Tue, 09 Oct 2018 14:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502734#M134250</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-10-09T14:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502737#M134252</link>
      <description>I add the double quotes and still do difference. Do you think that it may have to do with the fact that the FIND function already ask for double quote when you want to find a string? SAS might think that I am looking for the &amp;amp;yes_a word and not what is related to (i.e the word arrhytmia for example).</description>
      <pubDate>Tue, 09 Oct 2018 15:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502737#M134252</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-10-09T15:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find function with macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502785#M134273</link>
      <description>&lt;P&gt;Thanks to each of you for your answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I figured the solution by myself. I only added the trim function before calling my macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject_match; set subject;
   a = find(conclusion, trim("&amp;amp;yes_a");
   z = find(conclusion, trim("&amp;amp;no_a");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It worked perfectly as I wished.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 16:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-function-with-macro-variable/m-p/502785#M134273</guid>
      <dc:creator>dera</dc:creator>
      <dc:date>2018-10-09T16:22:55Z</dc:date>
    </item>
  </channel>
</rss>

