## macro numeric not equal operand

Solved
Super Contributor
Posts: 459

# macro numeric not equal operand

Hi,

I have a list of macro variables var1, var2 ... var&cnt that corresponds to variables.

For example, &var1 = price. I have a dataset with variables price_qc and price_cc, and if price_qc ne . then I want the new variable price = price_qc. Else, that is if price_qc is . , I want price = price_cc.

I am trying to do the following code:

``````%macro vars;
data want;
set have;
%do i = 1 %to &cnt;
%if &&var&i&'_qc' ne .   %then
&&var&i = &&var&i&'_qc'  ;
%else
&&var,i = &&var&i&'_cc';

%end;
run;
%mend;

%vars;``````

But I keep getting an error message:

"A character function was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

&&var&i&'_qc' ne . "

I tried different possibilities of operands, but the realized that even the = operand gets the same message.

Thank you

Accepted Solutions
Solution
‎10-01-2017 11:21 AM
Super User
Posts: 6,933

## Re: macro numeric not equal operand

A few changes:  removing quotes, removing the extra &, adding . to delimit macro variable names, changing %IF to IF:

%do i=1 %to &cnt;

if &&var&i.._qc ne . then &&var&i = &&var&i.._qc;

else &&var&i = &&var&i.._cc;

%end;

Also note, you may find it handy to examine the COALESCE function.

All Replies
Regular Contributor
Posts: 226

## Re: macro numeric not equal operand

Get rid of the qoutes around _qc and _cc. Hardly necessary to quote anything in macro code.
Solution
‎10-01-2017 11:21 AM
Super User
Posts: 6,933

## Re: macro numeric not equal operand

A few changes:  removing quotes, removing the extra &, adding . to delimit macro variable names, changing %IF to IF:

%do i=1 %to &cnt;

if &&var&i.._qc ne . then &&var&i = &&var&i.._qc;

else &&var&i = &&var&i.._cc;

%end;

Also note, you may find it handy to examine the COALESCE function.

☑ This topic is solved.