Hi, my question is pretty straightfoward. In this particular code I want to show two symbols in the legend. However, I am not sure how to write syntax to show a trianglefilled and starfilled in the legend. The legend is only populating with subjects that i'm plotting but I would like a legend that shows a star and a triangle so I can indicate one is for the first series and the other one is for the second series since it's all on the same graph. This is my code.
proc sgplot data=adef_bleed_part noautolegend dattrmap=MyAttrMap;
styleattrs datasymbols=(trianglefilled starfilled);
series x=astdy y=bleed_ep/
group=subjid markers markerattrs=( size=5 symbol=trianglefilled )
lineattrs=(pattern=5 thickness=.5) NOMISSINGGROUP name="series" attrid=myreg;
series x=stdy y=aval/
group=subjid markers markerattrs=( size=5 symbol=starfilled)
lineattrs=( pattern=1 thickness=2) NOMISSINGGROUP y2axis name="series2" attrid=myreg;
xaxis values=(0 to 2200 by 168) label="Study Day" minor;
yaxis values=(0 to 30 by 2) label="Cumulative Number of Bleeding Episodes" labelattrs=(size=7);
y2axis values=(0 to 200000 by 10000) label="Cumulative FIX Consumption (IU)" labelattrs=(size=7);
refline 365/transparency=0.5 label=("Year 1")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
refline 730/transparency=0.5 label=("Year 2")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
refline 1095/transparency=0.5 label=("Year 3")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
refline 1460/transparency=0.5 label=("Year 4")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
refline 1825/transparency=0.5 label=("Year 5")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
refline 2190/transparency=0.5 label=("Year 6")
labelattrs=(size=4 style=italic weight=bold color=red) lineattrs=(color=red pattern=34) labelloc=outside axis=x;
keylegend "series" "series2" / exclude=("") sortorder=ascending;
run;
quit;
Could you advise what I would need to do?
Hi, I figured this out using the legenditem condition.
I think to have a chance we need actual data to plot and the Dattrmap data set. You have a lot of options that interact around Group option behavior and we need all the info about your plots.
I am not clear if you want just a two-element "legend" (one triangle and one star) in addition to a legend based on your group values or in place of the group values.
Hi, I figured this out using the legenditem condition.
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!
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.