BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TrueTears
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Yes, that would mess things up! Try:

 

data somename;
set somename(rename=(
t_b_&input2.5=&input2
));
run;

Art, CEO, AnalystFinder.com

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.

TrueTears
Obsidian | Level 7

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?

 

art297
Opal | Level 21

Yes, that would mess things up! Try:

 

data somename;
set somename(rename=(
t_b_&input2.5=&input2
));
run;

Art, CEO, AnalystFinder.com

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4772 views
  • 1 like
  • 3 in conversation