Data visualization with SAS programming

Put marker on series data points for certain conditions using proc sgplot

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Put marker on series data points for certain conditions using proc sgplot

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

 


Accepted Solutions
Solution
‎08-20-2017 09:29 PM
SAS Super FREQ
Posts: 1,139

Re: Put marker on series data points for certain conditions using proc sgplot

[ Edited ]

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';

 

View solution in original post


All Replies
PROC Star
Posts: 653

Re: Put marker on series data points for certain conditions using proc sgplot

[ Edited ]

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;

  

New Contributor
Posts: 4

Re: Put marker on series data points for certain conditions using proc sgplot

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

Solution
‎08-20-2017 09:29 PM
SAS Super FREQ
Posts: 1,139

Re: Put marker on series data points for certain conditions using proc sgplot

[ Edited ]

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';

 

New Contributor
Posts: 4

Re: Put marker on series data points for certain conditions using proc sgplot

Hi Sanjay,

 

Thanks a lot. It works perfectly now.

 

Regards,

Ben

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 167 views
  • 2 likes
  • 3 in conversation