BookmarkSubscribeRSS Feed
thanksforhelp12
Calcite | Level 5

Hello,

 

I am attempting to draw a spaghetti plot that has a single line per subject but some subjects change groups during the study period (crossover) - for this subject, I want the single line to be two colors (eg red when group 1 and blue when group 2). How can I go about doing this? My current code is below not achieving the desired results. Basically for patients who switch treatment groups mid-study their line color should change when they switch. Thanks so much.

 

proc sgplot data=data;
  title 'Study Results by Treatment Group';
  series x=Time y=Score / group=patient 
               grouplc=arm name='grouping';
  keylegend 'grouping' / type=linecolor;
run;
5 REPLIES 5
Reeza
Super User
I would probably create a combined variable that indicates group and patient and then use a discrete attribute table to control the colours manually.
Rick_SAS
SAS Super FREQ

For a discussion and some code that describes Reeza's idea, see "Series plot with varying attributes" 

 

thanksforhelp12
Calcite | Level 5

Thanks to both of you. I actually stumbled upon that post incidentally this weekend.

 

So it seems if I have 100s of subjects I have to manually code every one of their lines?

Rick_SAS
SAS Super FREQ

Not necessarily. Post your data. Maybe the DATA step can produce the recoding automatically. Do you have SAS/IML?

Reeza
Super User

@thanksforhelp12 wrote:

Thanks to both of you. I actually stumbled upon that post incidentally this weekend.

 

So it seems if I have 100s of subjects I have to manually code every one of their lines?


Depends on how you define manually coding, but you should be able to have a data driven solution - I would assume you could use some basic IF/THEN statements to create your data appropriately. 

 

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1783 views
  • 1 like
  • 3 in conversation