SAS sgplot: how to get legend entries for multiple series and groups

168 Views Asked by At

I have the following code showing seven series of values (with each different colour) by age and for two periods t (one ends up solid the other dashed). I want to have each of the series names in the legend not the values of the t's which currently happens and isnt terribly helpful (see image), or maybe even a legend with series names by t values so there'd be 14 lables.

proc sgplot data=natempdisdat3;
    by sex;
    styleattrs datalinepatterns=(solid dash);
    
    series x=age y=LE / legendlabel='LE' name='LE' group=t lineattrs=(thickness=2 color=black);
    series x=age y=WLE / legendlabel='WLE' name='WLE' group=t lineattrs=(thickness=2 color=gray);
    series x=age y=DFLE / legendlabel='DFLE' name='DFLE' group=t lineattrs=(thickness=2 color=GREEN);
    series x=age y=NHNWLE / legendlabel='NHNWLE' name='NHNWLE' group=t lineattrs=(thickness=2 color=aquamarine);
    series x=age y=NHWLE / legendlabel='NHWLE' name='NHWLE' group=t lineattrs=(thickness=2 color=orange);
    series x=age y=HWLE / legendlabel='HWLE' name='HWLE' group=t lineattrs=(thickness=2 color=bippk);
    series x=age y=HNWLE / legendlabel='HNWLE' name='HNWLE' group=t lineattrs=(thickness=2 color=crimson);
 
    keylegend "LE" "WLE" "DFLE" "NHNWLE" "NHWLE" "HWLE" "HNWLE" / location=inside position=topright across=1;
run;

enter image description here

1

There are 1 best solutions below

0
On

When you are not adding the required filter then how do you expect to get the desired value, please change group=t with group=t groupdisplay=series on every occasion and see if it works.