BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sairampulipati
Fluorite | Level 6

Hello, 

I have the following sample data pchg has both positive and negative values ranging from -100 to 1000. I wanted plot a spaghetti plot and to have legend as cohort and each cohort has unique color irrespective of number of subjects in it. I am using the following code but unable to do coloring by cohort, is there any option in series line group = id, cohort. or is there any other option plot by id but color code by cohort and legend to be cohort. 

proc sgplot data=dta;
format visitc $visitfmt.;
series x=visitc y=pchg / group=id lineattrs=(pattern=solid thickness=1) break markers markerattrs=(symbol=circlefilled size=1.5);
xaxis type=discrete label='Visits' offsetmax=0.02 offsetmin=0.02;
yaxis label='Percent Change' ;
run;

c1.png

circlefilled option is not getting applied and hard to read this graph. 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Use the GROUPLC= option to specify that the line colors should be set by using the COHORT variable instead of the ID variable:

proc sgplot data=dta;
   *format visitc $visitfmt.;
   series x=visitc y=pchg / group=id GROUPLC=COHORT
          lineattrs=(pattern=solid thickness=1) 
          break markers markerattrs=(symbol=circlefilled size=2);
   xaxis type=discrete label='Visits' offsetmax=0.02 offsetmin=0.02;
   yaxis label='Percent Change' ;
   keylegend / type=linecolor title="";
run;

You can also use the TYPE=LINECOLOR option on the KEYLEGEND statement to add a legend for the cohorts.  

View solution in original post

5 REPLIES 5
Reeza
Super User

You'll probably want to control the colours manually in this case. 

You can use a data attribute map to assign colours. 

If you're not sure of what colours to use, I would suggest getting a set of 12 different colours from here and assign them as needed.

https://colorbrewer2.org/#type=qualitative&scheme=Paired&n=12

 

 

Rick_SAS
SAS Super FREQ

Use the GROUPLC= option to specify that the line colors should be set by using the COHORT variable instead of the ID variable:

proc sgplot data=dta;
   *format visitc $visitfmt.;
   series x=visitc y=pchg / group=id GROUPLC=COHORT
          lineattrs=(pattern=solid thickness=1) 
          break markers markerattrs=(symbol=circlefilled size=2);
   xaxis type=discrete label='Visits' offsetmax=0.02 offsetmin=0.02;
   yaxis label='Percent Change' ;
   keylegend / type=linecolor title="";
run;

You can also use the TYPE=LINECOLOR option on the KEYLEGEND statement to add a legend for the cohorts.  

Sairampulipati
Fluorite | Level 6

Thank you very much Rick. This is working but somehow circle filled is not populating in the figure. Do you have any suggestions please. 

Sairampulipati_0-1657114776520.png

 

Rick_SAS
SAS Super FREQ

use SIZE=6 instead of SIZE=2.

Sairampulipati
Fluorite | Level 6

Great, this is working great. Thank you so much Rick. 

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
  • 2174 views
  • 3 likes
  • 3 in conversation