11-30-2016 09:10 PM
I want to run something like below.
Any simple way to run %if &var_Status. not in ('XP','XC','TP') %then %do;
Below is the error what I get-
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: "&var_LastCampaignSetStatusCode." not in 'XP','XC','TP')
ERROR: The macro CHECKCONTROL will stop executing.
/*Get the status of previous campaign load*/
select ID, Status
into :var_ID, :var_Status
having ID = max(ID);
%if &var_Status. not in ('XP','XC','TP') %then %do;
/*Do something else*/
11-30-2016 10:08 PM
Macro language does contain an IN operator, but it is extremely tricky. I would recommend just spelling out the conditions in this case:
%if (&var_Status ne XP) and (&var_Status ne XC) and (&var_Status ne TP) %then %do;
11-30-2016 11:41 PM - edited 11-30-2016 11:42 PM
%if %sysfunc(findw(XP|XC|TP,&varstatus,|))=0 %then %do;
%if %sysfunc(findw(%str(XP,XC,TP),&varstatus,%str(,)))=0 %then %do;
12-01-2016 02:54 AM
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.
For the use of your intended construct, see http://support.sas.com/kb/31/322.html
Note the / minoperator option in the %macro statement.
So define your macro like that:
%macro checkcontrol / minoperator; . . . %if not(&var_Status. in XP XC TP) %then %do; . . . %mend;
12-01-2016 04:54 AM
This is matter of perspective really. You can simply the problem down to:
%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;
Assumes sorted. In fsct, depending on the previous code the above may not be necessary at all. 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.