BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

I am plotting a couple of groups on a single plot (Sirolimus and Tacrolimus), but I also need to plot some reference bands for each group.  Tacrolimus is easy enough because it's the same reference regardless of how many days the subject has been on study.  Sirolimus is slightly different in that the range is one range for days up to Day 90 and different for days after Day 90.  The way I am plotting right now, the reference band kind of angles downward at that 90-day break (based on the observed study day just prior and just after Day 90) when I basically want it to look like two rectangles offset from each other right at x=90.  Can someone help me clean up this code?

 

Attached is a Word document with 2 graphs.  The first graph is an example of what I want while the second graph is what I am getting.  (Please ignore any differences outside of the bands like missing dots on the plots since I have incomplete data at the moment).

 

Below is the code that I have developed.  And if you'll notice, the red band expands the whole width of the plotting area while the blue band expands the width of the observed data.  It would be nice if the blue bands could also stretch the width of the plotting area for consistency, but it's not required.

 

proc sql;
	create table trough_data (CM char(25), RESULT num, STDYDAY num);
		insert into trough_data (cm, result, stdyday)
			values ('Sirolimus Trough',14.1,-1)
			values ('Sirolimus Trough',8.4,3)
			values ('Sirolimus Trough',6.8,4)
			values ('Sirolimus Trough',23.6,8)
			values ('Sirolimus Trough',17.1,13)
			values ('Sirolimus Trough',14.3,32)
			values ('Sirolimus Trough',6.6,40)
			values ('Sirolimus Trough',8.5,49)
			values ('Sirolimus Trough',11.5,68)
			values ('Sirolimus Trough',10.5,81)
			values ('Sirolimus Trough',10,89)
			values ('Sirolimus Trough',10.4,96)
			values ('Sirolimus Trough',11.6,103)
			values ('Sirolimus Trough',8.3,110)
			values ('Sirolimus Trough',12.4,116)
			values ('Sirolimus Trough',12,181)
			values ('Sirolimus Trough',8,272)
			values ('Tacrolimus Trough',6.5,3)
			values ('Tacrolimus Trough',7.1,4)
			values ('Tacrolimus Trough',5.4,8)
			values ('Tacrolimus Trough',5.2,13)
			values ('Tacrolimus Trough',7.4,2)
			values ('Tacrolimus Trough',3.2,40)
			values ('Tacrolimus Trough',3.7,49)
			values ('Tacrolimus Trough',3.2,68)
			values ('Tacrolimus Trough',2.9,81)
			values ('Tacrolimus Trough',9.8,89)
			values ('Tacrolimus Trough',2.9,96)
			values ('Tacrolimus Trough',1.8,103)
			values ('Tacrolimus Trough',2.9,110)
			values ('Tacrolimus Trough',4.2,116)
			values ('Tacrolimus Trough',3.1,181);
quit;
data trough_data;
	set trough_data;
	if stdyday<=90 then do;
		LOW=10;
		HIGH=15;
	end;
	if stdyday>=90 then do;
		LOW=8;
		HIGH=12;
	end;
	label	result='ng/mL'
			stdyday='Study Day';
run;
proc sort data=trough_data;
	by stdyday cm;
run;

options orientation=landscape;
ods graphics / reset=all height=3in width=10.5in;
proc sgplot data=trough_data;
	styleattrs datalinepatterns=(solid);
	series x=stdyday y=result / group=cm name='plot1' markers markerattrs=(symbol=CircleFilled);
	band x=stdyday lower=3 upper=6 / fillattrs=(color=red transparency=0.85);
	band x=stdyday lower=low upper=high / fillattrs=(color=blue transparency=0.85);
	keylegend 'plot1' / position=right;
	xaxis grid values=(-50 to 400 by 50);
	yaxis grid values=(0 to 25 by 5);
run;

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

options orientation=landscape;
ods graphics / reset=all height=3in width=10.5in;
proc sgplot data=trough_data;
 styleattrs datalinepatterns=(solid);
 series x=stdyday y=result / group=cm name='plot1' markers markerattrs=(symbol=CircleFilled);
 band x=stdyday lower=3 upper=6 / fillattrs=(color=red transparency=0.85) ;

 step x=stdyday y=low  / justify=right name='x' lineattrs=(thickness=0);
    band x=stdyday lower=low upper=high / fillattrs=(color=blue transparency=0.85) type=step modelname='x';

 keylegend 'plot1' / position=right;
 xaxis grid values=(-50 to 400 by 50);
 yaxis grid values=(0 to 25 by 5);
run;

Ksharp_0-1682596226612.png

 

View solution in original post

2 REPLIES 2
whymath
Lapis Lazuli | Level 10

I modify the way you add variables low and high, also add a type=step option to the band statement.

proc sql;
	create table trough_data (CM char(25), RESULT num, STDYDAY num);
		insert into trough_data (cm, result, stdyday)
			values ('Sirolimus Trough',14.1,-1)
			values ('Sirolimus Trough',8.4,3)
			values ('Sirolimus Trough',6.8,4)
			values ('Sirolimus Trough',23.6,8)
			values ('Sirolimus Trough',17.1,13)
			values ('Sirolimus Trough',14.3,32)
			values ('Sirolimus Trough',6.6,40)
			values ('Sirolimus Trough',8.5,49)
			values ('Sirolimus Trough',11.5,68)
			values ('Sirolimus Trough',10.5,81)
			values ('Sirolimus Trough',10,89)
			values ('Sirolimus Trough',10.4,96)
			values ('Sirolimus Trough',11.6,103)
			values ('Sirolimus Trough',8.3,110)
			values ('Sirolimus Trough',12.4,116)
			values ('Sirolimus Trough',12,181)
			values ('Sirolimus Trough',8,272)
			values ('Tacrolimus Trough',6.5,3)
			values ('Tacrolimus Trough',7.1,4)
			values ('Tacrolimus Trough',5.4,8)
			values ('Tacrolimus Trough',5.2,13)
			values ('Tacrolimus Trough',7.4,2)
			values ('Tacrolimus Trough',3.2,40)
			values ('Tacrolimus Trough',3.7,49)
			values ('Tacrolimus Trough',3.2,68)
			values ('Tacrolimus Trough',2.9,81)
			values ('Tacrolimus Trough',9.8,89)
			values ('Tacrolimus Trough',2.9,96)
			values ('Tacrolimus Trough',1.8,103)
			values ('Tacrolimus Trough',2.9,110)
			values ('Tacrolimus Trough',4.2,116)
			values ('Tacrolimus Trough',3.1,181);
quit;
data trough_data;
	set trough_data end=eof;
  output;
  if eof then do;
    result=.;
    do stdyday=-60 to 410;    *A little exceeds graph x axis range[-50,400] to fill offset area;
      low=ifn(stdyday<90,10,8);
      high=ifn(stdyday<90,15,12);
      output;
    end;
  end;
	label	result='ng/mL'
			stdyday='Study Day';
run;
proc sort data=trough_data;
	by stdyday cm;
run;

options orientation=landscape;
ods graphics / reset=all height=3in width=10.5in;
proc sgplot data=trough_data;
	styleattrs datalinepatterns=(solid);
	series x=stdyday y=result / group=cm name='plot1' markers markerattrs=(symbol=CircleFilled);
	band x=stdyday lower=3 upper=6 / fillattrs=(color=red transparency=0.85);
	band x=stdyday lower=low upper=high / fillattrs=(color=blue transparency=0.85) type=step;
	keylegend 'plot1' / position=right;
	xaxis grid values=(-50 to 400 by 50);
	yaxis grid values=(0 to 25 by 5);
run;

 The result:

SGPlot.png

Ksharp
Super User

options orientation=landscape;
ods graphics / reset=all height=3in width=10.5in;
proc sgplot data=trough_data;
 styleattrs datalinepatterns=(solid);
 series x=stdyday y=result / group=cm name='plot1' markers markerattrs=(symbol=CircleFilled);
 band x=stdyday lower=3 upper=6 / fillattrs=(color=red transparency=0.85) ;

 step x=stdyday y=low  / justify=right name='x' lineattrs=(thickness=0);
    band x=stdyday lower=low upper=high / fillattrs=(color=blue transparency=0.85) type=step modelname='x';

 keylegend 'plot1' / position=right;
 xaxis grid values=(-50 to 400 by 50);
 yaxis grid values=(0 to 25 by 5);
run;

Ksharp_0-1682596226612.png

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 572 views
  • 1 like
  • 3 in conversation