I am using Proc SGPLOT to develop a Graph that represents Overlay of Individual and Mean Plasma Concentrations. X axis has ATPT variable for time point. On Y axis i have AVAL variable to present Individual Concentrations and a MEAN variable containing mean of all concentrations. Requirement is to plot both Individual and Mean Plasma Concentrations on single graph. There are 3 treatments, so i am expecting 3 pages for 3 treatments with each page presenting Overlay of Individual and Mean Plasma Concentrations.
I am using 2 series statement each for AVAL and Mean. The problem lies with sorting i think, for Individual Concentrations (AVAL) sorting needs to be done first by subjid and then ATPT to get spaghetti plot, but this sorting doesn't work with Mean plot as it needs to be sorted via time point first . Please see attached file to see Mock and actual Graph.
i am using below code :
proc sort data = pc2;
by trtan trta subjid atptn atpt;
run;
proc sgplot data = pc2 dattrmap = anno pad = (bottom = 20%) NOAUTOLEGEND ;
by trtan trta;
series x = atptn y = aval/ group = trta
lineattrs = (color = black thickness = 1 pattern = solid );
series x = atptn y = mean/ group = trta attrid = trtcolor
lineattrs = (thickness = 2 pattern = solid );
xaxis label= "Actual Time (h)"
labelattrs = (size = 10)
values = (0 12 24 36 48 72 96 120 168)
valueattrs = (size = 10)
grid;
yaxis label= "Plasma Concentration (ng/mL)"
labelattrs = (size = 10)
valueattrs = (size = 10)
grid;
run;
Hi @sas_user
Just a question:
in your sample date, the mean variable does not correspond to the mean of aval for a subjid in a specific treatment group (trtan) at a specific time point (atptn). Is it normal? How is the 'mean' calculated?
If it is a mistake maybe you could try the following:
proc sql;
create table pc3 as
select a.*, b.mean_atpt_overall
from
(select *, mean(aval) as mean_atpt_usbjid
from pc2
group by trtan, atpt ,subjid) as a
inner join
(select *, mean(aval) as mean_atpt_overall
from pc2
group by trtan, atpt) as b
on a.subjid=b.subjid and a.aval=b.aval and a.atptn=b.atptn and a.trta=b.trta
order by trtan, atptn, subjid;
run;
%macro plot (trtan);
proc sgplot data = pc3 /*dattrmap = anno*/ pad = (bottom = 20%) NOAUTOLEGEND ;
where trtan=&trtan.;
series x = atptn y = mean_atpt_usbjid / group=subjid
lineattrs = (color = black thickness = 1 pattern = solid);
series x = atptn y = mean_atpt_overall / attrid=trtcolor
lineattrs = (thickness = 2 pattern = solid);
title "Treatment = &trtan."; /*To be adapted*/
xaxis label= "Actual Time (h)"
labelattrs = (size = 10)
values = (0 12 24 36 48 72 96 120 168)
valueattrs = (size = 10)
grid;
yaxis label= "Plasma Concentration (ng/mL)"
labelattrs = (size = 10)
valueattrs = (size = 10)
grid;
run;
%mend;
%plot (1)
%plot (2)
Best,
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.