Hi,
I have a simple boxplot:
proc sgplot data=sashelp.cars;
vbox invoice/ category=type;
run;
Now, I want to annote this by adding some text (actually it's a number) above each box. I did somenthing like this:
data anno;
input function $ x1 $ y1 label;
datalines;
text Hybrid 150000 10
text SUV 150000 20
text Sedan 150000 30
text Sports 150000 15
text Truck 150000 5
text Wagon 150000 10
;
run;
proc sgplot data=sashelp.cars sganno=anno;
vbox invoice/ category=type;
run;
As a result I get the following error:
WARNING: The X1 option is the incorrect data type. The option will be ignored.
WARNING: The X1 option is the incorrect data type. The option will be ignored.
WARNING: The X1 option is the incorrect data type. The option will be ignored.
WARNING: The X1 option is the incorrect data type. The option will be ignored.
WARNING: The X1 option is the incorrect data type. The option will be ignored.
WARNING: The X1 option is the incorrect data type. The option will be ignored.
Could you tell me what's wrong and how to do it right?
Chris
This seems to put the same category value at the top of each box (at y=150,000). If user wants to put the numeric values on top of each box (category), I believe the x variable needs to match the character axis, using XC1 as the column in the anno data set. Personally, I would use a TEXT plot to draw these values (instead of annotation) as now VBOX allows overlays of basic plots.
I believe the default DRAWSPACE is GraphPercent. You need to change that to DataValue. Since x-axis is character, you will need to use XC1 as the column for a character value. Or, you can use the TEXT plot statement (9.4M3) or SCATTER plot with MARKERCHAR to do the same without annotation.
The data set that you are using for annotation is incorrect. You have switched the 'label' and x1 fields and you have not specified the coordinate systems. See if you can modify the following program to do what you want:
data anno;
retain function "text"
x1Space 'WallPercent'
y1Space 'DataValue'
x1 . y1 150000;
input label $ x1;
datalines;
Hybrid 8.3
SUV 25
Sedan 41.7
Sports 58.3
Truck 75
Wagon 91.7
;
proc sgplot data=sashelp.cars sganno=anno;
vbox invoice/ category=type;
run;
This seems to put the same category value at the top of each box (at y=150,000). If user wants to put the numeric values on top of each box (category), I believe the x variable needs to match the character axis, using XC1 as the column in the anno data set. Personally, I would use a TEXT plot to draw these values (instead of annotation) as now VBOX allows overlays of basic plots.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: