<?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: check a value in the macro variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123110#M25253</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To use the in operator in the macro facility you need to be using SAS 9.2 or SAS 9.3 and have 2 macro options set, minoperator and mindelimiter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is documented in the usage note, &lt;SPAN style="color: #000000; font-family: '.HelveticaNeueUI'; font-size: 15px; text-align: -webkit-auto;"&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/kb/35/591.html"&gt;http://support.sas.com/kb/35/591.html&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;- Click on the Full Code tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 29 Jun 2013 21:31:59 GMT</pubDate>
    <dc:creator>MichelleHomes</dc:creator>
    <dc:date>2013-06-29T21:31:59Z</dc:date>
    <item>
      <title>check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123109#M25252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;STRONG&gt;&lt;EM&gt;t&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;proc contents data=sashelp.class out=class_vards;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;select name into: varlst seperated by &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;','&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; from class_vards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%if&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;"Rating"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; in (&amp;amp;varlst) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; "it is in the list";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%else&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%return&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;t&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It says:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: red; font-size: 11pt;"&gt;ERROR: Required operator not found in expression: "Rating" in (&amp;amp;varlst)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I fix it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Jun 2013 20:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123109#M25252</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2013-06-29T20:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123110#M25253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To use the in operator in the macro facility you need to be using SAS 9.2 or SAS 9.3 and have 2 macro options set, minoperator and mindelimiter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is documented in the usage note, &lt;SPAN style="color: #000000; font-family: '.HelveticaNeueUI'; font-size: 15px; text-align: -webkit-auto;"&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/kb/35/591.html"&gt;http://support.sas.com/kb/35/591.html&lt;/A&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;- Click on the Full Code tab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Jun 2013 21:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123110#M25253</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2013-06-29T21:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123111#M25254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: navy; font-size: 11pt;"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;STRONG&gt;&lt;EM&gt;t&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;proc contents data=sashelp.class out=class_vards;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;select name into: varlst seperated by &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;','&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; from class_vards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%if&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;"Rating"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; NOT in (&amp;amp;varlst) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; "it is NOT in the list";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%else&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;%put "Yes, it is in the list, continue to process"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: navy; font-size: 11pt;"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;t&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Jun 2013 22:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123111#M25254</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2013-06-29T22:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123112#M25255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An alternative could be to use the %index macro function as in the SAS documentation, &lt;SPAN style="color: #000000; font-family: '.HelveticaNeueUI'; font-size: 15px; text-align: -webkit-auto;"&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543562.htm"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543562.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: '.HelveticaNeueUI'; font-size: 15px; text-align: -webkit-auto;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But this method would require you to write a macro do loop to pass each value to test it. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Jun 2013 23:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123112#M25255</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2013-06-29T23:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123113#M25256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;or try this one :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%macro t;
%local var;
proc sql noprint;
select name into: var from dictionary.columns where libname='SASHELP' and memname='CLASS' and upcase(name)='SEX';
quit;
%if &amp;amp;var ne %then %put "it is in the list";.
%else %return;
%mend;

%t
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan Opps, missing something&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Jun 2013 04:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123113#M25256</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-06-30T04:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: check a value in the macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123114#M25257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you cannot get MINOPERATOR options to work for you (or just because it is easier &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; ) you can use %SYSFUNC() to use the INDEXW() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro t;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%local class_vards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc contents noprint data=sashelp.class out=class_vards;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;select name into: varlst separated by ',' from class_vards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%if %sysfunc(indexw(%qupcase(&amp;amp;varlst),AGE,%str(,))) %then %put "it is in the list";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%else %return;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%t;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Other points:&lt;/P&gt;&lt;P&gt;Watch out for case when searching, you might want to add select UPCASE(NAME) in the SQL code.&lt;/P&gt;&lt;P&gt;Note that you do NOT want the double quotes as there will not be quotes in the value of the macro variable that PROC SQL generated. &lt;/P&gt;&lt;P&gt;Use the NOPRINT option on PROC CONTENTS and PROC SQL to avoid cluttering your SAS output.&lt;/P&gt;&lt;P&gt;Using comma as the delimiter makes the string harder to use in macro logic (that is why I used Qupcase function) and normal SAS code.&amp;nbsp; Why not use a space as the delimiter instead?&lt;/P&gt;&lt;P&gt;I would NOT use the %RETURN macro command as it violates the principle of single entry and single exit for program blocks.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jul 2013 03:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-value-in-the-macro-variable-list/m-p/123114#M25257</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-01T03:30:56Z</dc:date>
    </item>
  </channel>
</rss>

