data sampled;
infile datalines truncover;
input trtgrp subject time ipred ;
datalines;
1 1 0 0
1 1 0.4 7
1 1 0.7 11
1 1 1 15
1 1 2 20
1 1 3 23
1 1 5 20
1 1 6 17
1 1 8 19
1 1 10 16
1 2 0 0
1 2 0.6 7.74
1 2 1.04 10.4
1 2 2.99 17.2
1 2 3.84 17.6
1 2 6.22 16.4
1 2 8 18.4
1 2 10 16.5
;
run;
proc sgplot data=SAMPLED;
title 'Study Results by Subject';
series x=time y=IPRED / group=TRTgrp grouplc=TRTGRP name='grouping';
keylegend 'grouping' / type=linecolor;
run;
The graph has a line at the bottom connecting the 0 and 10 hr time point for subject 1. Can someone tell me why and how to get rid of the line?
@jacksonan123 wrote:
data sampled; infile datalines truncover; input trtgrp subject time ipred ; datalines; 1 1 0 0 1 1 0.4 7 1 1 0.7 11 1 1 1 15 1 1 2 20 1 1 3 23 1 1 5 20 1 1 6 17 1 1 8 19 1 1 10 16 1 2 0 0 1 2 0.6 7.74 1 2 1.04 10.4 1 2 2.99 17.2 1 2 3.84 17.6 1 2 6.22 16.4 1 2 8 18.4 1 2 10 16.5 ; run; proc sgplot data=SAMPLED; title 'Study Results by Subject'; series x=time y=IPRED / group=TRTgrp grouplc=TRTGRP name='grouping'; keylegend 'grouping' / type=linecolor; run;
The graph has a line at the bottom connecting the 0 and 10 hr time point for subject 1. Can someone tell me why and how to get rid of the line?
Are you sure you meant to use TRTgrp as the group variable? Since all of your records are from the same TRTGrp then that is what happens when the x values start over again for subject 2. See if using GROUP=SUBJECT creates the desired appearance.
@jacksonan123 wrote:
data sampled; infile datalines truncover; input trtgrp subject time ipred ; datalines; 1 1 0 0 1 1 0.4 7 1 1 0.7 11 1 1 1 15 1 1 2 20 1 1 3 23 1 1 5 20 1 1 6 17 1 1 8 19 1 1 10 16 1 2 0 0 1 2 0.6 7.74 1 2 1.04 10.4 1 2 2.99 17.2 1 2 3.84 17.6 1 2 6.22 16.4 1 2 8 18.4 1 2 10 16.5 ; run; proc sgplot data=SAMPLED; title 'Study Results by Subject'; series x=time y=IPRED / group=TRTgrp grouplc=TRTGRP name='grouping'; keylegend 'grouping' / type=linecolor; run;
The graph has a line at the bottom connecting the 0 and 10 hr time point for subject 1. Can someone tell me why and how to get rid of the line?
Are you sure you meant to use TRTgrp as the group variable? Since all of your records are from the same TRTGrp then that is what happens when the x values start over again for subject 2. See if using GROUP=SUBJECT creates the desired appearance.
What is your expected report?
Yes, that resolved the issue. My follow-up question is that the final data set will have separate treatment groups.
Therefore if I correctly interpret the expected result when I have more than one group would be to at that time have group=trtgrp and then it should plot ok?
@jacksonan123 wrote:
Yes, that resolved the issue. My follow-up question is that the final data set will have separate treatment groups.
Therefore if I correctly interpret the expected result when I have more than one group would be to at that time have group=trtgrp and then it should plot ok?
I think that you likely will want to insert a record at the end of each treatment subject combination with a missing Y value and use the BREAK option on the series statement to prevent the connection from last subject to next. Obviously the data below for trtgrp 2 is made up by me and has no actual relationship to your values. With my example data the appearance is actually the same for Group=trtgrp or Group=subject.
I would also suggest a label for your legend.
data sampled; infile datalines truncover; input trtgrp subject time ipred ; datalines; 1 1 0 0 1 1 0.4 7 1 1 0.7 11 1 1 1 15 1 1 2 20 1 1 3 23 1 1 5 20 1 1 6 17 1 1 8 19 1 1 10 16 1 2 0 0 1 2 0.6 7.74 1 2 1.04 10.4 1 2 2.99 17.2 1 2 3.84 17.6 1 2 6.22 16.4 1 2 8 18.4 1 2 10 16.5 2 3 0 0 2 3 0.8 8.0 2 3 1.1 9.9 2 3 4.60 14.50 2 3 7.1 13.9 2 3 9.50 12.80 2 4 0 0 2 4 0.3 5.0 2 4 2.80 13.0 2 4 5.0 16.60 2 4 8.70 16.40 2 4 9.30 13.40 ; run; proc sort data=sampled; by trtgrp subject time; run; data plot; set sampled; by trtgrp subject; output; if last.subject then do; ipred=.; output; end; run; proc sgplot data=plot; title 'Study Results by Subject'; series x=time y=IPRED / group=TRTGRP grouplc=TRTGRP break name='grouping'; keylegend 'grouping' / type=linecolor; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.