03-26-2017 09:03 AM
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?
03-26-2017 11:18 AM
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.
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.
03-26-2017 03:43 PM
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?
Need further help from the community? Please ask a new question.