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;
For a discussion and some code that describes Reeza's idea, see "Series plot with varying attributes"
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?
Not necessarily. Post your data. Maybe the DATA step can produce the recoding automatically. Do you have SAS/IML?
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.