Data visualization with SAS programming

Resolving macro variables in SGPLOT titles or inset

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Resolving macro variables in SGPLOT titles or inset

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


Accepted Solutions
Solution
‎10-27-2017 10:17 AM
SAS Super FREQ
Posts: 496

Re: Resolving macro variables in SGPLOT titles or inset

View solution in original post


All Replies
SAS Super FREQ
Posts: 496

Re: Resolving macro variables in SGPLOT titles or inset

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

Contributor
Posts: 22

Re: Resolving macro variables in SGPLOT titles or inset

Posted in reply to WarrenKuhfeld

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

Super Contributor
Posts: 261

Re: Resolving macro variables in SGPLOT titles or inset

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;

 

Solution
‎10-27-2017 10:17 AM
SAS Super FREQ
Posts: 496

Re: Resolving macro variables in SGPLOT titles or inset

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 260 views
  • 1 like
  • 3 in conversation