Desktop productivity for business analysts and programmers

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand

Hi All  ,

 

The Following code in my program gives me the weird error messages and sometime it runs without any error and most of the time ended up in log file with error .

 

/* **************************************  MACRO to Ensure Not to print If the Dataset is empty ********************/
%macro ChkDSEmpty(Table_Name);
	/* Init check flag */
	%let dsempty=0;

	/* create empty test data set by removing all records */
	data Table_Name;
		set Table_Name;
	run;

	/* Check for empty data */
	data _null_;
		if eof then
			do;
				call symput('dsempty',1);
				put 'NOTE: EOF - no records in data!';
			end;

		stop;
		set &Table_Name end=eof;
	run;

%mend ChkDSEmpty;

%ChkDSEmpty(SOURCEDUPLICATE);

/******************************** 1094_SUMMARY_REPORTS - creation  ******************************/
%macro Export;
	%if &dsempty. %then
		%do;
			%put WARNING: Export step skipped - no output records.;
		%end;
	%else
		%do;
			/*source duplicate html creation*/
			ods html file ='/mnt/agrm-rrr/1094_sourceduplicate.html' style=sasweb;

			PROC REPORT DATA=sourceduplicate NOWD;
				COL CDNUMPOL count;
				title "B2W 1094 Source Duplicate";
				Define  CDNUMPOL   / display 'CDNUMPOL';
				Define  count   / display 'count';
			RUN;

			ods _all_ close;
			ods html close;
		%end;
%mend Export;

%Export

The Issue arise at %Export Section  and its not resolving ..

 

I'm currently using SAS EG ver 7.12 (7.100.2.3350) (32-bit).

 

Looking forward your reply folks ,..

 

 

Thanks in Advance ,

Srini.


Accepted Solutions
Solution
‎08-07-2017 06:59 AM
Super User
Posts: 7,854

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Posted in reply to srinidelite

When you define dsempty in the first macro, it will be stored in the local symbol table of that macro, and not be available anywhere else.

Use the %global statement to put it in the global symbol table.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎08-07-2017 06:59 AM
Super User
Posts: 7,854

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Posted in reply to srinidelite

When you define dsempty in the first macro, it will be stored in the local symbol table of that macro, and not be available anywhere else.

Use the %global statement to put it in the global symbol table.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 20

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Posted in reply to KurtBremser

Thank you so much .

 

This solution resolved all of existing issues . Thanks a ton

Super Contributor
Posts: 345

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Posted in reply to srinidelite

Have a look at sashelp.vtable, the dataset contains various information about datasets available in the active sas session. The following code sets dsemtpy to 1 if the dataset is empty.

 

proc sql noprint;
   select (nobs=0)
      into :dsempty trimmed
         from sashelp.vtable
            where libname = 'SASHELP' and MemName = 'CLASS'
      ;
quit;
Super User
Super User
Posts: 7,988

Re: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric oper

Posted in reply to srinidelite

You can simplfy that to:

 

data _null_;
  set sashelp.vtable (where=(libname="<your lib>" and memname="<your dataset>"));
  if nobs=0 then call execute('%put "No obs found";');
  else call execute(' ods html file ="/mnt/agrm-rrr/1094_sourceduplicate.html" style=sasweb;
                			proc report data=sourceduplicate nowd;
                				col cdnumpol count;
                				title "B2W 1094 Source Duplicate";
                				define  cdnumpol   / display "CDNUMPOL";
                				define  count   / display "count";
                			run;
                			ods html close;');
run;

Or if you prefer to have the report in a macro then just:

 

data _null_;
  set sashelp.vtable (where=(libname="<your lib>" and memname="<your dataset>"));
  call execute(ifc(nobs=0,'%put "No obs found";','%PrintFile;'));
run;

Assuming report macro is called PrintFile.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 182 views
  • 0 likes
  • 4 in conversation