Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Variable. 2

Status
Not open for further replies.

shenniko

Programmer
Apr 15, 2005
52
US
Hi Guys need some help,

Have the following code below:-

Code:
proc sql noprint;
  select count (Holiday) into :count_Line
  from Merged
  Where Holiday ne "";
quit;
%if (&count_Line ne 0) %then
	%do;
		%ChkHolidays();
	%end;

Which does a count on the holiday Field in the Merged Table and puts that count into a Variable. then checks to see if the count is ne 0, if so then run a macro called ChkHolidays.

But im getting the below error, and im not sure why..

Code:
WARNING: Apparent symbolic reference COUNT_LINE not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: (&count_Line ne 0)
ERROR: The macro BANKHOLIDAYS will stop executing.
MLOGIC(BANKHOLIDAYS):  Ending execution.

Im thinking that because there is no data in the "Holidays" column, then for some reason its not creating the Variable Count_Line (correct?) if so, is there some function to check if a variable has been set or made?

Any Ideas?

Thanks in advance

Shenn
 
Shenniko,
The problem occurs when the macro variable count_Line does not get set (initialized). This can occur when your dataset has no records that meet the 'where' criteria that you set up. The SQL procedure fails (perhaps generates a warning in the log) and never creates the Macro var count_Line. When your macro IF statement tries to resolve you get an ERROR.

There are several ways around this problem. First you can pre-initialize the count_line macro variable to blank like this:
Code:
%let count_Line =;
or you can use the %superq() macro function around the potential macro variable count_Line.

I hope that this helps you,
Klaz
 
You can also declare the macro variable, without setting it:-
Code:
%local count_Line;
This binds the macro variable to the current macro so it will not be available outside it.
If you want itto be available elsewhere...
Code:
%global count_line;
%local can only be used in a macro definition, %global can be used in either macro defs or open code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top