BookmarkSubscribeRSS Feed
sghatak
Fluorite | Level 6

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.

5 REPLIES 5
Reeza
Super User

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;


 

Reeza
Super User
You also seem to have both a variable and macro variable that named CYM1?
sghatak
Fluorite | Level 6

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;

Kurt_Bremser
Super User

 


@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.

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 939 views
  • 0 likes
  • 4 in conversation