- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.