i keep getting the following error:-
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: E_START_DATE&i not in ('') and &CYm1=0
ERROR: The macro MONTHELIG will stop executing.
Absolutely not able to debug this -
%macro monthelig;
%let i=1;
%do %while (&i <7);
%let CYm1=0;
data test;
set test_0;
%if E_START_DATE&i not in ('') and &CYm1=0 %then
%do;
if E_START_DATE&i<='01APR2018'd<=E_END_DATE&i then
CYm1=1;
else
CYm1=0;
%end;
%else %if E_START_DATE&i not in ('') and &CYm1=1 %then
%do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=1 %then
%do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=0 %then
%do;
CYm1=0;
%end;
run;
%let i=%sysevalf(&i+1);
%put i=&i;
%end;
%mend monthelig;
%monthelig;
Any help or suggestion, I would appreciate it very much. Thank you.
Please reformat your code so it's correct, you seem to have text in the middle.
Turn on the debugging options from your program, run it and then post the full log with the errors so we can better help you debug your code.
options mprint symbolgen;
Without your data we can't run the code.
@sghatak wrote:
i keep getting the following error:-
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: E_START_DATE&i not in ('') and &CYm1=0
ERROR: The macro MONTHELIG will stop executing.
Absolutely not able to debug this -
%macro monthelig;
%let i=1;
%do %while (&i <7);
%let CYm1=0;
data test;
Any help or suggestion, I would appreciate it very much. Thank you.
set test_0;
%if E_START_DATE&i not in ('') and &CYm1=0 %then %do;
if E_START_DATE&i<='01APR2018'd<=E_END_DATE&i then CYm1=1;
else CYm1=0;
%end;
%else %if E_START_DATE&i not in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=0 %then %do;
CYm1=0;
%end;
run;
%let i=%sysevalf(&i+1);
%put i=&i;
%end;
%mend monthelig;
%monthelig;
Thank you , i could figure out the issues. Corrected code:-
options mprint symbolgen;
%macro monthelig;
%let CYm1=0;
%let i=1;
%do %while (&i <7);
data test;
set test_0;
%if E_START_DATE&i<='01APR2018'd<=E_END_DATE&i and &CYm1=0 %then %do;
CYm1=1;
%end;
%else %if E_START_DATE&i not in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=0 %then %do;
CYm1=0;
%end;
run;
%let i=%sysevalf(&i+1);
%put i=&i;
%end;
%mend monthelig;
%monthelig;
@sghatak wrote:
Thank you , i could figure out the issues. Corrected code:-
options mprint symbolgen;
%macro monthelig;
%let CYm1=0;
%let i=1;
%do %while (&i <7);
data test;
set test_0;
%if E_START_DATE&i<='01APR2018'd<=E_END_DATE&i and &CYm1=0 %then %do;
CYm1=1;
%end;
%else %if E_START_DATE&i not in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=1 %then %do;
CYm1=1;
%END;
%else %if E_START_DATE&i in ('') and &CYm1=0 %then %do;
CYm1=0;
%end;
run;
%let i=%sysevalf(&i+1);
%put i=&i;
%end;
%mend monthelig;
%monthelig;
This won't work either, for the reasons @Astounding already gave. You need to understand what the macro PREprocessor does before you start using it.
First, you need to understand that macro language has zero ability to inspect the value of a DATA step variable. Your code expects that it can, but it just plain can't. Never.
Recommendation: you would be best served by constructing a program with no macro language in it. Use SAS language only, and get a version of your program that works the way you would want it to when &i is 1. Once you have a working DATA step, we can talk about how to write a macro language loop. But not before.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: