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


Hi,

I am looking to customize a scatterplot produced with SGPLOT in the following ways:

1. Highlight specific data points

    A. Highlight one data point in one color

    B. Highlight a group of data points (not criteria A) in a second color

    C. Highlight the other points that do not meet criteria A and B in a third color

2. Superimpose two lines -

     A. One at a given point on the y axis

     B. One at a given point on the x axis.

Sample data is attached.

1A. Pick one id, for example, AB212, and fill the point one color (e.g. blue)

1B. Since AB212 is a part of group 1, fill all data points in group 1 a second color (e.g. purple)

1C. Every other data point (groups in (2, 3)) , fill a third color (e.g. green)

2A. Create a black line (thin) across the xaxis for the xline value

2B. Create a black line (thin) across the yaxis for the yline value.

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Add the following code to your sample data. Simply change the SELECT_ID macro variable to the ID of interest, and the code will take care of the rest. Let me know if you have any questions about it.

Thanks!
Dan

/*-----------------------------------------------------------------------------------------------------------------*/

%let select_id=AB212;

/* Find the group of interest */

data _null_;

set test;

if (id eq &select_id) then call symput('ACTIVEGROUP', group);

run;

data plotdata;

length grpstr $ 15;

label grpstr="ID";

set test;

ref_x = .;

ref_y = .;

if (id eq "&select_id") then do;

  grpstr="&select_id";

  ref_x = x;

  ref_y = y;

end;

else if (group eq symget('ACTIVEGROUP')) then grpstr="In same group";

else grpstr="In other groups";

run;

data attrmap;

retain id "grpmap" markersymbol "circlefilled";

input value $ 1-15 markercolor $ 16-22;

cards;

In other groups green

In same group   purple

_other_         blue

;

run;

proc sgplot data=plotdata dattrmap=attrmap;

scatter x=x y=y / group=grpstr attrid=grpmap;

refline ref_x / axis=x label;

refline ref_y / label;

run;

View solution in original post

4 REPLIES 4
DanH_sas
SAS Super FREQ

What version of SAS do you have?

OPHD1
Fluorite | Level 6

Hi Dan, 9.3

DanH_sas
SAS Super FREQ

Add the following code to your sample data. Simply change the SELECT_ID macro variable to the ID of interest, and the code will take care of the rest. Let me know if you have any questions about it.

Thanks!
Dan

/*-----------------------------------------------------------------------------------------------------------------*/

%let select_id=AB212;

/* Find the group of interest */

data _null_;

set test;

if (id eq &select_id) then call symput('ACTIVEGROUP', group);

run;

data plotdata;

length grpstr $ 15;

label grpstr="ID";

set test;

ref_x = .;

ref_y = .;

if (id eq "&select_id") then do;

  grpstr="&select_id";

  ref_x = x;

  ref_y = y;

end;

else if (group eq symget('ACTIVEGROUP')) then grpstr="In same group";

else grpstr="In other groups";

run;

data attrmap;

retain id "grpmap" markersymbol "circlefilled";

input value $ 1-15 markercolor $ 16-22;

cards;

In other groups green

In same group   purple

_other_         blue

;

run;

proc sgplot data=plotdata dattrmap=attrmap;

scatter x=x y=y / group=grpstr attrid=grpmap;

refline ref_x / axis=x label;

refline ref_y / label;

run;

OPHD1
Fluorite | Level 6

Thank you so much Dan. I made a few changes and this works perfectly for what I was looking for. I really appreciate it.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1703 views
  • 0 likes
  • 2 in conversation