Data visualization with SAS programming

Problem with Using ATTRMAP for One Value in SGPLOT Graph

Accepted Solution Solved
Reply
Occasional Contributor svh
Occasional Contributor
Posts: 16
Accepted Solution

Problem with Using ATTRMAP for One Value in SGPLOT Graph

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;

Accepted Solutions
Solution
Tuesday
SAS Super FREQ
Posts: 1,042

Re: Problem with Using ATTRMAP for One Value in SGPLOT Graph

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


All Replies
Solution
Tuesday
SAS Super FREQ
Posts: 1,042

Re: Problem with Using ATTRMAP for One Value in SGPLOT Graph

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;

 

☑ This topic is solved.

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

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