<?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: sas macro how to check a value in a list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450067#M283691</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201636"&gt;@luu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;How can I using macro to check if a value is in a list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have a macro variable 'med_rx',&lt;/P&gt;
&lt;P&gt;%let med_rx=7804;&lt;/P&gt;
&lt;P&gt;And i have a variable list&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var_list;&lt;BR /&gt;1007383 1012123 103755 1151123 1151126 1151127 1151130&amp;nbsp;...823181 866331 8785 995869&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can i check if 'med_rx' is in 'var_list'? Is there any way to do it like&amp;nbsp;" if &amp;amp;med_var in &amp;amp;&lt;SPAN&gt;var_list then ..." in the macro?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not what I would think of as a variable list. A variable list would typically contain the names of Variables. That looks more like a value list. At which point it becomes likely to be a case of how are you using this? Sometimes this sort of question indicates some attempting to do the data manipulation in macro code that better fits in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%eval( %sysfunc(findw(&amp;amp;varlist,&amp;amp;med_rx)) &amp;gt; 0)&lt;/PRE&gt;
&lt;P&gt;Will return a value of 1 (true) when the med_rx is an entire word in the varlist and 0 if not found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER the value is a macro variable and as such data step IF as you showed would be inappropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if &amp;amp;med_rx in (&amp;amp;varlist) then do &amp;lt;something&amp;gt;&lt;/PRE&gt;
&lt;P&gt;would be valid in a data step. However the values of the macro variables would be set before the data step compiles and would not be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any values of variables in the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how /where do you intend to use this comparison?&lt;/P&gt;</description>
    <pubDate>Fri, 30 Mar 2018 21:09:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-03-30T21:09:53Z</dc:date>
    <item>
      <title>sas macro how to check a value in a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450063#M283690</link>
      <description>&lt;P&gt;How can I using macro to check if a value is in a list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have a macro variable 'med_rx',&lt;/P&gt;&lt;P&gt;%let med_rx=7804;&lt;/P&gt;&lt;P&gt;And i have a variable list&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var_list;&lt;BR /&gt;1007383 1012123 103755 1151123 1151126 1151127 1151130&amp;nbsp;...823181 866331 8785 995869&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i check if 'med_rx' is in 'var_list'? Is there any way to do it like&amp;nbsp;" if &amp;amp;med_var in &amp;amp;&lt;SPAN&gt;var_list then ..." in the macro?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 20:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450063#M283690</guid>
      <dc:creator>luu</dc:creator>
      <dc:date>2018-03-30T20:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro how to check a value in a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450067#M283691</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201636"&gt;@luu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;How can I using macro to check if a value is in a list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have a macro variable 'med_rx',&lt;/P&gt;
&lt;P&gt;%let med_rx=7804;&lt;/P&gt;
&lt;P&gt;And i have a variable list&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var_list;&lt;BR /&gt;1007383 1012123 103755 1151123 1151126 1151127 1151130&amp;nbsp;...823181 866331 8785 995869&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can i check if 'med_rx' is in 'var_list'? Is there any way to do it like&amp;nbsp;" if &amp;amp;med_var in &amp;amp;&lt;SPAN&gt;var_list then ..." in the macro?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not what I would think of as a variable list. A variable list would typically contain the names of Variables. That looks more like a value list. At which point it becomes likely to be a case of how are you using this? Sometimes this sort of question indicates some attempting to do the data manipulation in macro code that better fits in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%eval( %sysfunc(findw(&amp;amp;varlist,&amp;amp;med_rx)) &amp;gt; 0)&lt;/PRE&gt;
&lt;P&gt;Will return a value of 1 (true) when the med_rx is an entire word in the varlist and 0 if not found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HOWEVER the value is a macro variable and as such data step IF as you showed would be inappropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if &amp;amp;med_rx in (&amp;amp;varlist) then do &amp;lt;something&amp;gt;&lt;/PRE&gt;
&lt;P&gt;would be valid in a data step. However the values of the macro variables would be set before the data step compiles and would not be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any values of variables in the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how /where do you intend to use this comparison?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 21:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450067#M283691</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-30T21:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: sas macro how to check a value in a list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450070#M283692</link>
      <description>&lt;P&gt;Thank you for your reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are right, this is a value list instead of a variable list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your answer can solve my problem! I will check it. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 21:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macro-how-to-check-a-value-in-a-list/m-p/450070#M283692</guid>
      <dc:creator>luu</dc:creator>
      <dc:date>2018-03-30T21:20:21Z</dc:date>
    </item>
  </channel>
</rss>

