I am a beginner SAS coder and I have the following (excerpt) SAS macro:
%macro bts(input1, input2);
proc sql noprint;
select count(*) into :num_record
from b.&input1;
quit;
%put &num_record;
proc sql;
create table c.datafile as
select
sqrt(&num_record)*(m_&input2/s_&input2+1/3*sum(x_&input2)/(&num_record*s_&input2**3)*(m_&input2/s_&input2)**2+1/(6*&num_record)*sum(x_&input2)/(&num_record*s_&input2**3)) as &input2
from
(select
mean(&input2) as m_&input2, std(&input2) as s_&input2, (&input2-calculated m_&input2)**3 as x_&input2
from b.&input1);
quit;
%mend;
%bts(inv_per, cr_6m);
The error that I get is:
WARNING: Apparent symbolic reference M_ not resolved. &m_cr_6m
The variable cr_6m just consists of numbers and I think the reason I'm getting an error is because of the underscores. How can I fix this?
Yes, that would mess things up! Try:
data somename; set somename(rename=( t_b_&input2.5=&input2 )); run;
Art, CEO, AnalystFinder.com
I cannot see how you would get that error message from the code you posted. Can you post the log instead? You could turn on the MPRINT option to see what code the macro is generating.
It really looks like the error message is generated from code like this with a space after the underscore.
&m_ cr_6m
There is also a posibility that you are trying to generate macro variable name on the fly from other macro variables and the SAS parser is getting confused. This can sometimes be solved by either deriving the name first before using it.
%let suffix = cr_6m ;
%let mvar= m_&suffix ;
%put value = &&mvar ;
Or by wrapping the expression in %UNQUOTE() function.
Ahh, I think I realized my mistake, actually it was in another line:
data somename;
set somename(rename=(
t_b_&input25=&input2
));
run;
The actual name for the variable to be renamed is t_b_cr_6m5, but it's not recognizing the &input2 as cr_6m in the renaming command, how can I fix this?
Yes, that would mess things up! Try:
data somename; set somename(rename=( t_b_&input2.5=&input2 )); run;
Art, CEO, AnalystFinder.com
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.