BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
benparado
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;

  

benparado
Calcite | Level 5

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

Jay54
Meteorite | Level 14

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

 

benparado
Calcite | Level 5

Hi Sanjay,

 

Thanks a lot. It works perfectly now.

 

Regards,

Ben

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 2282 views
  • 2 likes
  • 3 in conversation