BookmarkSubscribeRSS Feed
sas_user
Calcite | Level 5

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;
3 REPLIES 3
ed_sas_member
Meteorite | Level 14

Hi @sas_user 

 

Could you please supply some sample data in DATALINES ?

 

Best,

sas_user
Calcite | Level 5
data dummy;
infile datalines delimiter = ',' missover;
input subject treatment $ trtnum aval atpt $ atptn mean;

datalines;

101,Trt1,1,55.75,0.5 hours,0.5,500.06694121
101,Trt1,1,2655.7,0.5 hours,0.5,500.06694121
101,Trt1,1,4.7635874439,0.5 hours,0.5,500.06694121
101,Trt1,1,67.51,1 hours,1,1393.5436913
101,Trt1,1,3364.56,1 hours,1,1393.5436913
101,Trt1,1,4.9837949933,1 hours,1,1393.5436913
101,Trt1,1,71.7,2 hours,2,1306.3579924
101,Trt1,1,3006.92,2 hours,2,1306.3579924
101,Trt1,1,4.1937517434,2 hours,2,1306.3579924
101,Trt1,1,96.42,4 hours,4,1157.3195013
101,Trt1,1,3088.92,4 hours,4,1157.3195013
101,Trt1,1,3.2036092097,4 hours,4,1157.3195013
101,Trt1,1,59.24,6 hours,6,1102.2535578
101,Trt1,1,2339.75,6 hours,6,1102.2535578
101,Trt1,1,3.9496117488,6 hours,6,1102.2535578
102,Trt1,1,45.75,0.5 hours,0.5,456.06694121
102,Trt1,1,4567.7,0.5 hours,0.5,456.06694121
102,Trt1,1,8.7635874439,0.5 hours,0.5,456.06694121
102,Trt1,1,23.51,1 hours,1,1567.5436913
102,Trt1,1,1234.56,1 hours,1,1567.5436913
102,Trt1,1,4.9837949933,1 hours,1,1567.5436913
102,Trt1,1,45.7,2 hours,2,1000.3579924
102,Trt1,1,3456.92,2 hours,2,1000.3579924
102,Trt1,1,8.1937517434,2 hours,2,1000.3579924
102,Trt1,1,34.42,4 hours,4,1157.3195013
102,Trt1,1,8907.92,4 hours,4,1157.3195013
102,Trt1,1,56.2036092097,4 hours,4,1157.3195013
102,Trt1,1,12.24,6 hours,6,1201.2535578
102,Trt1,1,123.75,6 hours,6,1201.2535578
102,Trt1,1,1.9496117488,6 hours,6,1201.2535578
;
run;


Hope it helps.
ed_sas_member
Meteorite | Level 14

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-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 852 views
  • 0 likes
  • 2 in conversation