BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

I have been asked to produce a series of boxplots with overlaid scatterplots. I would like to use the DATTRMAP statement in SGPLOT to assign a specific style to the point for my institution on the plot. I'm also using the DATALABEL statement to add some text. However, I cannot get the SGPLOT procedure to pick up the style elements that I have put into the ATTRMAP data set. The following code produces the boxplot, but my institution just has the label and no other unique style attributes. I've looked around for answers, but I cannot determine what is interfering with SGPLOT using the style attributes in  ATTRMAP 

 

data attrmap;
PUT id $CHAR20.;
put value $char15.;
put markersymbol $CHAR20.;
id= 'LABELVALUE'; value='MYPOINT'; markersymbol='SquareFilled'; markercolor='Green'; output;
run;

DATA HAVE;
INPUT ID $ GROUP $ VALUE LABELVALUE $ @;
METRIC = 'ADMIT_RATE';
CARDS;
01 OTHERS .214 .
02 OTHERS .100 .
03 OTHERS .765 . 
04 OURS   .421 MYPOINT
05 OTHERS .133 .
06 OTHERS .211 .
07 OTHERS .300 .
08 OTHERS .105 .
09 OTHERS .204 .
10 OTHERS .090 .
;
RUN;
proc sgplot data=HAVE noautolegend dattrmap=attrmap ;
vbox  VALUE / category=METRIC boxwidth=0.4 nooutliers ;
scatter  x=METRIC y=VALUE / datalabel=labelvalue jitter transparency=0.4
         markerattrs=(color=red symbol=CircleFilled) ATTRID=LABELVALUE;
refline .50 / LABEL = 'Avg. for Comparators';
yaxis offsetmax=0.1;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

There were two issues:

1. You needed to have a GROUP on your SCATTER plot for the attrmap to be used.

2. The MARKERATTRS overrides the attributes from the attrmap. Instead, create an _OTHER_ entry in the attrmap to provide the default symbol appearance.

 

Hope this helps!

Dan

 

data attrmap;
PUT id $CHAR20.;
put value $char15.;
put markersymbol $CHAR20.;
id= 'LABELVALUE'; value='MYPOINT'; markersymbol='SquareFilled'; markercolor='Green'; output;
id= 'LABELVALUE'; value='_OTHER_'; markersymbol='CircleFilled'; markercolor='Red'; output;
run;
proc print data=attrmap; run;
DATA HAVE;
INPUT ID $ GROUP $ VALUE LABELVALUE $ @;
METRIC = 'ADMIT_RATE';
CARDS;
01 OTHERS .214 .
02 OTHERS .100 .
03 OTHERS .765 .
04 OURS   .421 MYPOINT
05 OTHERS .133 .
06 OTHERS .211 .
07 OTHERS .300 .
08 OTHERS .105 .
09 OTHERS .204 .
10 OTHERS .090 .
;
RUN;

ods _all_ close;
ods html path="." (url=none) file="temp.html";

proc sgplot data=HAVE noautolegend dattrmap=attrmap ;
vbox  VALUE / category=METRIC boxwidth=0.4 nooutliers ;
scatter  x=METRIC y=VALUE / datalabel=labelvalue jitter transparency=0.4 group=labelvalue ATTRID=LABELVALUE;
refline .50 / LABEL = 'Avg. for Comparators';
yaxis offsetmax=0.1;
run;

ods html close;

 

View solution in original post

1 REPLY 1
DanH_sas
SAS Super FREQ

There were two issues:

1. You needed to have a GROUP on your SCATTER plot for the attrmap to be used.

2. The MARKERATTRS overrides the attributes from the attrmap. Instead, create an _OTHER_ entry in the attrmap to provide the default symbol appearance.

 

Hope this helps!

Dan

 

data attrmap;
PUT id $CHAR20.;
put value $char15.;
put markersymbol $CHAR20.;
id= 'LABELVALUE'; value='MYPOINT'; markersymbol='SquareFilled'; markercolor='Green'; output;
id= 'LABELVALUE'; value='_OTHER_'; markersymbol='CircleFilled'; markercolor='Red'; output;
run;
proc print data=attrmap; run;
DATA HAVE;
INPUT ID $ GROUP $ VALUE LABELVALUE $ @;
METRIC = 'ADMIT_RATE';
CARDS;
01 OTHERS .214 .
02 OTHERS .100 .
03 OTHERS .765 .
04 OURS   .421 MYPOINT
05 OTHERS .133 .
06 OTHERS .211 .
07 OTHERS .300 .
08 OTHERS .105 .
09 OTHERS .204 .
10 OTHERS .090 .
;
RUN;

ods _all_ close;
ods html path="." (url=none) file="temp.html";

proc sgplot data=HAVE noautolegend dattrmap=attrmap ;
vbox  VALUE / category=METRIC boxwidth=0.4 nooutliers ;
scatter  x=METRIC y=VALUE / datalabel=labelvalue jitter transparency=0.4 group=labelvalue ATTRID=LABELVALUE;
refline .50 / LABEL = 'Avg. for Comparators';
yaxis offsetmax=0.1;
run;

ods html close;

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1063 views
  • 0 likes
  • 2 in conversation