<?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: validating macro parameter using IN() statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472757#M121246</link>
    <description>&lt;P&gt;See if&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas&lt;/A&gt; meets your needs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, if not, perhaps you can use it as a starting point for your own generic macro parameter validation macro.&lt;/P&gt;</description>
    <pubDate>Sun, 24 Jun 2018 04:35:26 GMT</pubDate>
    <dc:creator>ScottBass</dc:creator>
    <dc:date>2018-06-24T04:35:26Z</dc:date>
    <item>
      <title>validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472621#M121199</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro which needs to validate keyword parameters against a list. The code below distills the issue (the actual macro is much more complex).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO CONVERTOR (CONVERSION_TYPE = );

  %IF &amp;amp;CONVERSION_TYPE IN (MILES_TO_METERS,MILES_TO_FEET) %THEN %DO;
    %LET ORIGINAL_UNIT = MILES;
	                                                       %END;

%MEND;

%CONVERTOR (CONVERSION_TYPE = MILES_TO_METERS);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Executing this yields the following error in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;ERROR: Required operator not found in expression: &amp;amp;CONVERSION IN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (MILES_TO_METERS,MILES_TO_FEET)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please point out the correct way to do this? It seems that SAS doesn't allow the IN operator within a macro code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 22:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472621#M121199</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-06-22T22:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472627#M121204</link>
      <description>&lt;P&gt;Try using&lt;/P&gt;&lt;PRE&gt; *macro IN operator;
  options minoperator mindelimiter=',';&lt;/PRE&gt;&lt;P&gt;specify the correct delimiter&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 22:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472627#M121204</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-22T22:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472629#M121206</link>
      <description>&lt;P&gt;Historically IN was not a macro operation, but it was added at some point in the last decade. For backward compatibility the old functionality remains and you have to specify the options. I think you may also need a space between the words? Or at least it helps to make it legible and easier to debug.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find it easiest to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Set options permanently as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;2) Set it specifically for each macro to avoid unexpected behaviour.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also like to add an %ELSE and %PUT to my tests to make it clear where my logic is failing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO CONVERTOR (CONVERSION_TYPE = ) / minoperator mindelimiter=',';

  %IF &amp;amp;CONVERSION_TYPE IN (MILES_TO_METERS, MILES_TO_FEET) %THEN %DO;
    %PUT ORIGINAL_UNIT = MILES;
	                                                       %END;
   %ELSE %PUT Logic failed;

%MEND;

%CONVERTOR (CONVERSION_TYPE = MILES_TO_METERS);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 22:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472629#M121206</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-22T22:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472659#M121215</link>
      <description>&lt;P&gt;In addition to specifying the two options ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Off the top of my head and untested ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do NOT use parentheses around the list of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do NOT add a space on either side of the delimiter.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 02:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472659#M121215</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-23T02:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472671#M121223</link>
      <description>&lt;P&gt;Trying to us IN as an operator in macro code is tricky, and probably not worth it.&amp;nbsp;&amp;nbsp;If you do want to use it then make sure to tell the macro compiler that you want to use it and what character to use as the delimiter. It is generally a bad idea to use a comma as a delimiter in macro code as it can cause trouble when trying to pass values into macro functions (or macro calls) since comma is used as the delimiter between arguments (parameters).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro convertor(conversion_type) / minoperator mindelimiter='|';
%local original_unit ;
%if &amp;amp;conversion_type in miles_to_meters|miles_to_feet %then %do;
  %let original_unit = %scan(&amp;amp;conversion_type,1,_);
%end;
%else %put WARNING: Conversion_type not recognized. &amp;amp;=conversion_type;
%put &amp;amp;=conversion_type &amp;amp;=original_unit ;
%mend;

%convertor(conversion_type = miles_to_meters);
%convertor(conversion_type = pounds_to_dollars);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 04:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472671#M121223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-23T04:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472757#M121246</link>
      <description>&lt;P&gt;See if&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas&lt;/A&gt; meets your needs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or, if not, perhaps you can use it as a starting point for your own generic macro parameter validation macro.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jun 2018 04:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/472757#M121246</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2018-06-24T04:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: validating macro parameter using IN() statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/473048#M121342</link>
      <description>&lt;P&gt;Thank you all for responding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In light of the added complexity, I'll just use the OR operator&amp;nbsp;....but it's good to know how properly use the IN() operator&amp;nbsp;if needed in the future! A requirement&amp;nbsp;of this&amp;nbsp;particular&amp;nbsp;macro is&amp;nbsp;maintainability by "non SAS experts" hence it would be inappropriate to&amp;nbsp;rely on options or other such dependencies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO CONVERTOR (CONVERSION_TYPE = );

  %IF &amp;amp;CONVERSION_TYPE = MILES_TO_METERS  OR  &amp;amp;CONVERSION_TYPE = MILES_TO_FEET  %THEN %DO;
    %LET ORIGINAL_UNIT = MILES;
	                                                       %END;

%MEND;

%CONVERTOR (CONVERSION_TYPE = MILES_TO_METERS);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 15:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/validating-macro-parameter-using-IN-statement/m-p/473048#M121342</guid>
      <dc:creator>desertsp</dc:creator>
      <dc:date>2018-06-25T15:33:22Z</dc:date>
    </item>
  </channel>
</rss>

