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

 

i have similar situation in link below. my question is this is individual plot with many lines.

but for legend, i just want to specify the color by group.

for example, in FreelanceReinh Jade's post: 

series x=avisit y=aval / group=usubjid attrid=myid;

 for legend, instead of list usubjids, just want to list legend as blue for trta='A' and red for trta='B'. how do i do that? thanks.

 

Solved: How Can I Specify Line Colors per Group in SG Plot? - SAS Support Communities

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

You need to use a secondary classifier on the SERIES plot, and tell the legend to show only the line color. Here is an example using the data from the other post:

 

data test;
    input usubjid$ trta$ avisit$ aval;
    datalines;
    xx-01 A Day1 10
    xx-01 A Day5 11
    xx-02 A Day1  9
    xx-02 A Day5 10
    xx-03 B Day1 20
    xx-03 B Day5 17
    xx-04 B Day1 19
    xx-04 B Day5 21
    ;
run;
proc sgplot data=test;
    series x=avisit y=aval / group=usubjid grouplc=trta;
    keylegend / type=linecolor title="TRTA";
run;

 

 

View solution in original post

1 REPLY 1
DanH_sas
SAS Super FREQ

You need to use a secondary classifier on the SERIES plot, and tell the legend to show only the line color. Here is an example using the data from the other post:

 

data test;
    input usubjid$ trta$ avisit$ aval;
    datalines;
    xx-01 A Day1 10
    xx-01 A Day5 11
    xx-02 A Day1  9
    xx-02 A Day5 10
    xx-03 B Day1 20
    xx-03 B Day5 17
    xx-04 B Day1 19
    xx-04 B Day5 21
    ;
run;
proc sgplot data=test;
    series x=avisit y=aval / group=usubjid grouplc=trta;
    keylegend / type=linecolor title="TRTA";
run;

 

 

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
  • 1 reply
  • 291 views
  • 4 likes
  • 2 in conversation