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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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.

View solution in original post

4 REPLIES 4
Jay54
Meteorite | Level 14

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.

Rick_SAS
SAS Super FREQ

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; 
Jay54
Meteorite | Level 14

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.

chris2377
Quartz | Level 8

@Jay54

Thanks a lot! I didn't think of overlaying the two plots. 

 

But I'll still try to achieve the same output using annotate. @Rick_SAS, thanks for the tips!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2136 views
  • 0 likes
  • 3 in conversation