DATA Step, Macro, Functions and more

SGPLOT

Accepted Solution Solved
Reply
Highlighted
Frequent Contributor
Posts: 142
Accepted Solution

SGPLOT

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?


Accepted Solutions
Solution
Friday
Super User
Posts: 13,913

Re: SGPLOT

Posted in reply to jacksonan123

@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


All Replies
Solution
Friday
Super User
Posts: 13,913

Re: SGPLOT

Posted in reply to jacksonan123

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

PROC Star
Posts: 624

Re: SGPLOT

Posted in reply to jacksonan123

What is your expected report?

Thanks,
Suryakiran
Frequent Contributor
Posts: 142

Re: SGPLOT

Posted in reply to SuryaKiran

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?

Super User
Posts: 13,913

Re: SGPLOT

Posted in reply to jacksonan123

@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;
Frequent Contributor
Posts: 142

Re: SGPLOT

Thanks for the update and I will use your suggestion for my final plot.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 72 views
  • 0 likes
  • 3 in conversation