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
@djrisks is correct that you can use %global. You can also specify 'G' as the last argument to symputx. Note that your question is about the scope of macro variables not about SGPLOT. https://blogs.sas.com/content/sgf/2015/02/13/sas-macro-variables-how-to-determine-scope/
That will work if you generated the macro variable &log_p in the global symbol table. Perhaps you have the wrong name?
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
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;
@djrisks is correct that you can use %global. You can also specify 'G' as the last argument to symputx. Note that your question is about the scope of macro variables not about SGPLOT. https://blogs.sas.com/content/sgf/2015/02/13/sas-macro-variables-how-to-determine-scope/
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.