<?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 Can we use Macro Variable with single quotes to use it in &amp;quot;IN&amp;quot; operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847171#M334951</link>
    <description>&lt;P&gt;I have the following scenario.&amp;nbsp; I am want to use multiple 'sex ' criteria to subset the data. Is it possible? what's the best way to achieve it to control sub setting conditions. In the below example I want flexibility where I can enter one or two observation for &amp;amp;sex macro variable. Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %macro filter(sex= );
  data class;
  set sashelp.class;
  if upcase(sex) in ( "&amp;amp;sex");
  *if upcase (sex) in ('F' 'M'); *how to achieve this using macro variable:
  run;
  %mend;
 %filter( sex= F );
 %*filter ( sex = %nrbquote('F' 'M'));*I wanna use like this or any other alternatives to call macro;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Dec 2022 01:35:16 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-12-01T01:35:16Z</dc:date>
    <item>
      <title>Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847171#M334951</link>
      <description>&lt;P&gt;I have the following scenario.&amp;nbsp; I am want to use multiple 'sex ' criteria to subset the data. Is it possible? what's the best way to achieve it to control sub setting conditions. In the below example I want flexibility where I can enter one or two observation for &amp;amp;sex macro variable. Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %macro filter(sex= );
  data class;
  set sashelp.class;
  if upcase(sex) in ( "&amp;amp;sex");
  *if upcase (sex) in ('F' 'M'); *how to achieve this using macro variable:
  run;
  %mend;
 %filter( sex= F );
 %*filter ( sex = %nrbquote('F' 'M'));*I wanna use like this or any other alternatives to call macro;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 01:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847171#M334951</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-12-01T01:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847180#M334954</link>
      <description>A few possible combinations will do this, but here is perhaps the simplest.&lt;BR /&gt;&lt;BR /&gt;First, get rid of the double quotes:&lt;BR /&gt;&lt;BR /&gt;if upcase(sex) in ( &amp;amp;sex );&lt;BR /&gt;&lt;BR /&gt;Then call the macro supplying the characters that should replace &amp;amp;sex:&lt;BR /&gt;&lt;BR /&gt;%filter (sex = 'F' 'M')</description>
      <pubDate>Thu, 01 Dec 2022 01:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847180#M334954</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-12-01T01:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847213#M334965</link>
      <description>&lt;P&gt;Try FINDW() function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro filter(sex= );
  data class;
  set sashelp.class;
  if  findw("&amp;amp;sex",strip(upcase(sex)));
  run;
  %mend;
 %filter ( sex =F  M )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 08:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847213#M334965</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-01T08:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847241#M334978</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the following scenario.&amp;nbsp; I am want to use multiple 'sex ' criteria to subset the data. Is it possible? what's the best way to achieve it to control sub setting conditions. In the below example I want flexibility where I can enter one or two observation for &amp;amp;sex macro variable. Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %macro filter(sex= );
  data class;
  set sashelp.class;
  if upcase(sex) in ( "&amp;amp;sex");
  *if upcase (sex) in ('F' 'M'); *how to achieve this using macro variable:
  run;
  %mend;
 %filter( sex= F );
 %*filter ( sex = %nrbquote('F' 'M'));*I wanna use like this or any other alternatives to call macro;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Remember that when you execute code that contains macros and macro variables, the values of the macro variables are used in place of the actual macro variable to generate code. Your macro above would, when executed, produce this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if upcase(sex) in ( "'F' 'M'");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this will not match the sex values in SASHELP.CLASS which are &lt;FONT face="courier new,courier"&gt;'F'&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;'M'&lt;/FONT&gt;, it will match a record if the value of sex is &lt;FONT face="courier new,courier"&gt;"'F' 'M'"&lt;/FONT&gt;, but there is no such record that has this value for sex. So you really need to "envision" what the code generated by the macro will be. Hence, when&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;tells you that you should remove the double quotes around &amp;amp;sex and use&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;%filter (sex = 'F' 'M')&lt;/FONT&gt;, then this will produce the line of code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if upcase(sex) in ( 'F' 'M');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;which is what you really want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In addition, you could turn on macro debugging options&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;before you run your macro, and then you can see in the log that the code generated is not what you want it to be:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MPRINT(FILTER):    data class;
MPRINT(FILTER):   set sashelp.class;
MPRINT(FILTER):   if upcase(sex) in ( "'F' 'M'");
MPRINT(FILTER):   run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847241#M334978</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-01T13:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847250#M334985</link>
      <description>&lt;P&gt;Since you mentioned flexibility, an alternate design would be to allow the user to pass any subsetting expression,&amp;nbsp; not just values to allow subsetting by gender.&amp;nbsp; Sometimes I do stuff like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro filter(where=1 );
  data class;
    set sashelp.class;
    where &amp;amp;where;
  run;
  proc print data=class ;
  run ;
%mend;

%filter()
%filter(where=(sex='F') )
%filter(where=(sex IN ('F','M')) )  /*this comma is not a problem because the parentheses mask it*/
%filter(where=(age&amp;lt;15))
%filter(where=(Name =: 'J' and age&amp;lt;=13))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For a utility macro that is designed to be used by a SAS programmer, I find the flexibility of allowing them to provide any valid WHERE clause is often valuable.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847250#M334985</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-12-01T13:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use Macro Variable with single quotes to use it in "IN" operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847319#M335007</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; providing me the flexible options.&lt;/P&gt;
&lt;P&gt;Thank you every one who provided the different ways to achieve the solutions. I really appreciate taking your time to&amp;nbsp; answer this and providing insights how to use the code more&amp;nbsp; useful way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 19:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-Macro-Variable-with-single-quotes-to-use-it-in-quot/m-p/847319#M335007</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-12-01T19:22:24Z</dc:date>
    </item>
  </channel>
</rss>

