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
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.