BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10
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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

View solution in original post

5 REPLIES 5
ballardw
Super User

@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.

SuryaKiran
Meteorite | Level 14

What is your expected report?

Thanks,
Suryakiran
jacksonan123
Lapis Lazuli | Level 10

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?

ballardw
Super User

@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;
jacksonan123
Lapis Lazuli | Level 10
Thanks for the update and I will use your suggestion for my final plot.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 860 views
  • 0 likes
  • 3 in conversation