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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1309 views
  • 1 like
  • 3 in conversation