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: Call for Content

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!

Submit your idea!

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