Hi,
Is there anyway I can put a marker on data points on certain conditions using proc sgplot? For the below codes, I would like to put an Orange-filled circle marker for series "Actual DR" when column 'significant'=1 and a Red-filled circle marker when column 'signficant'=2. When 'significant'=0, then there will be no marker.
data defaults;
input obs_month assignpd dftrate obsmth $ significant;
datalines;
201301 0.0012 0.0000 Jan-13 0
201302 0.0012 0.0001 Feb-13 0
201303 0.0012 0.0003 Mar-13 0
201304 0.0012 0.0008 Apr-13 0
201305 0.0012 0.0015 May-13 1
201306 0.0012 0.0009 Jun-13 0
201307 0.0012 0.0011 Jul-13 0
201308 0.0012 0.0019 Aug-13 1
201309 0.0012 0.0025 Sep-13 1
201310 0.0012 0.0034 Oct-13 2
201311 0.0012 0.0030 Nov-13 2
201312 0.0012 0.0027 Dec-13 1
201401 0.0012 0.0023 Jan-14 1
201402 0.0012 0.0023 Feb-14 1
201403 0.0012 0.0043 Mar-14 2
201404 0.0012 0.0040 Apr-14 2
201405 0.0012 0.0038 May-14 2
;
run;
proc sgplot data=defaults;
series x=obsmth y=dftrate / legendlabel="Actual DR" lineattrs=(thickness=2 color=blue);
series x=obsmth y=assignpd / legendlabel="Assigned PD" lineattrs=(thickness=2 color=black);
xaxis label="Months" fitpolicy=rotatethin valuesrotate=vertical;
yaxis label="Default Rate";
run;
Thanks a lot for your help.
Regards,
Ben
The default legend will include all plot statements. You can customize it by giving names to the two plots you want included, and then specify these in the KEYLEGEND statement. This will display information from only the two series plots into the legend.
scatter x=obsmth y=dftrate / <options>;
series x=obsmth y=dftrate / <your options> name='a';
series x=obsmth y=assignpd / <your options> name='b';
keylegend 'a' 'b';
I think this is easier to do with an additional SERIES statement and controlling shape and color with a STYLEATTRS statement like this
proc sgplot data=defaults;
styleattrs datacontrastcolors =(white orange red) datasymbols=(circlefilled);
scatter x=obsmth y=dftrate / group=significant;
series x=obsmth y=dftrate / legendlabel="Actual DR" lineattrs=(thickness=2 color=blue);
series x=obsmth y=assignpd / legendlabel="Assigned PD" lineattrs=(thickness=2 color=black);
xaxis label="Months" fitpolicy=rotatethin valuesrotate=vertical;
yaxis label="Default Rate";
run;
Hi Draycut,
Thanks a lot for your reply. Your solution works perfectly. However, there's one minor observation. The legend on the graph now shows the values of the "significant" field.
Is there anyway not to show this and instead show the legend of the "Actual DR" and "Assigned PD" ?
Thanks again.
Regards,
Ben
The default legend will include all plot statements. You can customize it by giving names to the two plots you want included, and then specify these in the KEYLEGEND statement. This will display information from only the two series plots into the legend.
scatter x=obsmth y=dftrate / <options>;
series x=obsmth y=dftrate / <your options> name='a';
series x=obsmth y=assignpd / <your options> name='b';
keylegend 'a' 'b';
Hi Sanjay,
Thanks a lot. It works perfectly now.
Regards,
Ben
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.