<?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: Macro if not in (char list) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315811#M270874</link>
    <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(findw(XP|XC|TP,&amp;amp;varstatus,|))=0 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;%do;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%if&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(findw(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%str&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(XP,XC,TP),&amp;amp;varstatus,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%str&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(,)))=0 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%then&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%do&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2016 04:42:58 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2016-12-01T04:42:58Z</dc:date>
    <item>
      <title>Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315758#M270872</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want&amp;nbsp;to run something like below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any simple way to run&amp;nbsp;&lt;SPAN&gt;%if &amp;amp;var_Status. not in ('XP','XC','TP') %then %do;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Below is the error what I get-&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: "&amp;amp;var_LastCampaignSetStatusCode." not in :('XP','XC','TP') &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: The macro CHECKCONTROL will stop executing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro CheckControl;&lt;BR /&gt; /*Get the status of previous campaign load*/&lt;BR /&gt; proc sql;&lt;BR /&gt; select ID, Status&lt;BR /&gt; into :var_ID, :var_Status&lt;BR /&gt; from SomeTable&lt;BR /&gt; having ID = max(ID);&lt;BR /&gt; quit;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;var_Status. not in ('XP','XC','TP') %then %do;&lt;BR /&gt; /*Do something*/&lt;BR /&gt; %end;&lt;BR /&gt; %else %do;&lt;BR /&gt; /*Do something else*/&lt;BR /&gt; %end&lt;BR /&gt; %mend CheckControl;&lt;BR /&gt; %CheckControl;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 02:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315758#M270872</guid>
      <dc:creator>aj34321</dc:creator>
      <dc:date>2016-12-01T02:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315769#M270873</link>
      <description>&lt;P&gt;Macro language does contain an IN operator, but it is extremely tricky. &amp;nbsp;I would recommend just spelling out the conditions in this case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if (&amp;amp;var_Status ne XP) and (&amp;amp;var_Status ne XC) and (&amp;amp;var_Status ne TP) %then %do;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 03:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315769#M270873</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-01T03:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315811#M270874</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(findw(XP|XC|TP,&amp;amp;varstatus,|))=0 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;%do;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%if&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%sysfunc&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(findw(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%str&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(XP,XC,TP),&amp;amp;varstatus,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%str&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;(,)))=0 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%then&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="SAS Monospace"&gt;&lt;FONT color="#0000ff" face="SAS Monospace"&gt;%do&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 04:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315811#M270874</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-01T04:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315846#M270875</link>
      <description>&lt;P&gt;Since the macro processor only knows one data type (text), quotes are not necessary and wrong in most places. You also must not use commas to separate the values in your list.&lt;/P&gt;
&lt;P&gt;For the use of your intended construct, see &lt;A href="http://support.sas.com/kb/31/322.html" target="_blank"&gt;http://support.sas.com/kb/31/322.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Note the / minoperator option in the %macro statement.&lt;/P&gt;
&lt;P&gt;So define your macro like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro checkcontrol / minoperator;

.
.
.

%if not(&amp;amp;var_Status. in XP XC TP) %then %do;

.
.
.

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2016 07:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315846#M270875</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-01T07:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315869#M270876</link>
      <description>&lt;P&gt;This is matter of perspective really. &amp;nbsp;You can simply the problem down to:&lt;/P&gt;
&lt;PRE&gt;%macro CheckControl();
  ...
%mend CheckControl;

data _null_;
  set sometable;
  by id;
  if last.id and var_status in ('XP','XC','TP') then 
    call execute('%CheckControl;');
run;&lt;/PRE&gt;
&lt;P&gt;Assumes sorted. &amp;nbsp;In fsct, depending on the previous code the above may not be necessary at all. &amp;nbsp;Quite a lot of the conditional macro logic is just put in programs due to the process being badly thought out, or previous decisions making processing further down a program harder than they need to be.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 09:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/315869#M270876</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-01T09:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/600471#M270877</link>
      <description>&lt;P&gt;This structure works. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 17:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/600471#M270877</guid>
      <dc:creator>chinli72</dc:creator>
      <dc:date>2019-10-30T17:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/781311#M270878</link>
      <description>&lt;P&gt;I use the same structure and get error message. Could you please let me which part goes wrong in my code? Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro loop_thru_fcat_list;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local i next_name;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let i=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while (%scan(&amp;amp;fcat_name, &amp;amp;i) ne );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; %let next_name = %scan(&amp;amp;fcat_name, &amp;amp;i);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; %if not(&amp;amp;NEXT_NAME. in C1_EST FIBRINO) %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; %cbs_fcat(&amp;amp;NEXT_NAME);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; %let i = %eval(&amp;amp;i + 1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend loop_thru_fcat_list;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;operand is required. The condition was: not(&amp;amp;NEXT_NAME. in C1_EST FIBRINO)&lt;BR /&gt;ERROR: The macro LOOP_THRU_FCAT_LIST will stop executing.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 16:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/781311#M270878</guid>
      <dc:creator>bing2202</dc:creator>
      <dc:date>2021-11-19T16:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro if not in (char list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/781318#M270879</link>
      <description>&lt;P&gt;You have to tell SAS that you want the macro processor to treat the text IN as an operator.&amp;nbsp; You also need to tell it what delimiter to use between the items in the list.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop_thru_fcat_list / minoperator mindelimiter=' ';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also have to watch out for text like OR that might be confused for an operator. So use %QSCAN() instead of %SCAN().&lt;/P&gt;
&lt;P&gt;Also your macro is referencing a macro variable that is neither an input nor a local macro variable. Much better to be explicit about the source of the inputs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop_thru_fcat_list(fcat_name) / minoperator mindelimiter=' ';
%local i next_name;
%do i=1 %to %sysfunc(countw(&amp;amp;fcat_name));
   %let next_name = %qscan(&amp;amp;fcat_name, &amp;amp;i);
   %if not(&amp;amp;NEXT_NAME. in C1_EST FIBRINO) %then %do;
     %PUT &amp;amp;=i &amp;amp;=NEXT_NAME ;
   %end;
%end;
%mend loop_thru_fcat_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's test it:&lt;/P&gt;
&lt;PRE&gt;11    %loop_thru_fcat_list(a or b);
I=1 NEXT_NAME=a
I=2 NEXT_NAME=or
I=3 NEXT_NAME=b
&lt;/PRE&gt;
&lt;P&gt;If we use %SCAN() instead of %QSCAN() you can see the error:&lt;/P&gt;
&lt;PRE&gt;12    %macro loop_thru_fcat_list(fcat_name) / minoperator mindelimiter=' ';
13    %local i next_name;
14    %do i=1 %to %sysfunc(countw(&amp;amp;fcat_name));
15       %let next_name = %scan(&amp;amp;fcat_name, &amp;amp;i);
16       %if not(&amp;amp;NEXT_NAME. in C1_EST FIBRINO) %then %do;
17         %PUT &amp;amp;=i &amp;amp;=NEXT_NAME ;
18       %end;
19    %end;
20    %mend loop_thru_fcat_list;
21
22    %loop_thru_fcat_list(a or b);
I=1 NEXT_NAME=a
ERROR: Operand missing for IN operator in argument to %EVAL function.
ERROR: The macro LOOP_THRU_FCAT_LIST will stop executing.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Nov 2021 17:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-if-not-in-char-list/m-p/781318#M270879</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-19T17:01:48Z</dc:date>
    </item>
  </channel>
</rss>

