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

Hello,

 

I would like to produce a series of KM plots which I'm writing in a macro using SGPLOT. I want to add the logrank p-value to each plot. Is there a way resolve marcro variables in the inset statement?

 

Using call symputx I have assigned a macro variable &log_p to contain the relevant p-value.

 

ods listing gpath="&outpath\" image_dpi=300  style=tfl;
ods graphics / imagename="KM time to death ARM" reset=index height=5in width=6in;

proc sgplot data=survest1_e04brand noautolegend;
	step x=end_time y=survival / group=e04brand name="km";
	xaxis values=(0 to 56 by 7) label="Follow-up (Days)";
	yaxis values=(0 to 1 by 0.2) label="Probability of Survival";
	keylegend "km" / location=inside position=bottomright down=2 noborder;
	xaxistable atrisk / x=risk_time location=outside position=bottom class=e04brand title="N at Risk";
	inset "Log-Rank test P=&log_p" / position=bottomleft;
run;

However, when I run this code I get the warning statement apparent symbolic reference not resolved and the text '&log_p' appears in the output graph rather than the value I would like it to resolve to.

 

Is there a way around this?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Ammonite | Level 13

View solution in original post

4 REPLIES 4
WarrenKuhfeld
Ammonite | Level 13

That will work if you generated the macro variable &log_p in the global symbol table.  Perhaps you have the wrong name?

DGrint
Obsidian | Level 7

The &log_p variable is generated in a datastep like so:

%macro km(...);

...

data _null_; set logrank; pval=round(probchisq,10**(-1*(abs(int(log10(abs(probchisq))))+2))); if test='Log-Rank' then call symputx('log_p',pval); run; %put &log_p;

%mend;

 

The problem is that this data step is within a user defined macro, while I was testing the sgplot graph output outside. So the log_p macro was not global. 

 

Is there a way to make this log_p macro available globally even though it is defined with call symputx within the km user defined macro?

 

Thanks

djrisks
Barite | Level 11

Hello,

 

Can you use the following?

%macro km(...);...

%global log_p;

data _null_;
set logrank;
pval=round(probchisq,10**(-1*(abs(int(log10(abs(probchisq))))+2)));
if test='Log-Rank' then call symputx('log_p',pval);
run;

or 

 

%macro km(...);...data test;
	set logrank;
	pval=round(probchisq,10**(-1*(abs(int(log10(abs(probchisq))))+2)));
	if test='Log-Rank';
run;

proc sql;
  select pval into :log_p
  from test;
quit;


%put &log_p;%mend;

 

WarrenKuhfeld
Ammonite | Level 13

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 3466 views
  • 1 like
  • 3 in conversation