BookmarkSubscribeRSS Feed
marianhabesland
Calcite | Level 5

I have this code so far for making a box plot:

 

TITLE "Diastolic Blood Pressure by Ethnicity/Race Group" BOLD;
PROC SGPLOT DATA = HypAnl.HypPrimanl;
VBOX DBP / GROUP = EthRaceCd
FILLATTRS= (COLOR=LIGHTRED) LINEATTRS= (COLOR=BLACK);
YAXIS LABEL = "Latest DBP Measurement"
LABELATTRS=(Weight=Bold)
VALUES = (10 TO 100 BY 10);
XAXIS LABEL = "Ethnicity/Race Group"
LABELATTRS=(Weight=Bold);
REFLINE 90 / LABEL= "Hypertension Threshold"
LINEATTRS= (COLOR=RED);
INSET "Data Source: HypAnl.HypPrimAnl (As of December 31, 2014)";
RUN;

 

My current box plot looks like this:

Screen Shot 2017-11-29 at 15.50.08.png

 

And I want it to look like the one below. Specifically what I want to change is that the groups (Hispanic, NH Asian etc) actually appear on the X-axis with gridlines. Any ideas?

 

Screen Shot 2017-11-29 at 15.48.09.png

 

7 REPLIES 7
ballardw
Super User

To get axis labels try using Category=EthRaceCd instead of Group=

 

To your Yaxis statement add GRID to get gridlines at the tick marks.

Gridattrs would be used to control the appearance of the grid lines.

marianhabesland
Calcite | Level 5

When I change group to category it does show the label like I want it, but it also only produces one box plot, like this:

Screen Shot 2017-11-29 at 16.58.54.png

ballardw
Super User

Show data in the form of a data step and the actual code you used with category.

 

I have pages of output with category and get one box for each level of the category variable.

marianhabesland
Calcite | Level 5

 I am using a data file that is formatted like this. These are the two variables that are included in the box plot. The code I provided over is the entire code that I used to produce the box plot.

 

Screen Shot 2017-11-29 at 17.52.33.png

 

 

Reeza
Super User

Switching to Category worked for me. What exact version of SAS do you have, I'm using 9.4M3

 

TITLE "Diastolic Blood Pressure by Ethnicity/Race Group" BOLD;

PROC SGPLOT DATA = sashelp.heart;
	VBOX diastolic / category = smoking_status
		FILLATTRS= (COLOR=LIGHTRED) LINEATTRS= (COLOR=BLACK);
	
	REFLINE 90 / LABEL= "Hypertension Threshold"
		LINEATTRS= (COLOR=RED);

	INSET "Data Source: HypAnl.HypPrimAnl (As of December 31, 2014)";

	YAXIS LABEL = "Latest DBP Measurement"
		LABELATTRS=(Weight=Bold)
		VALUES = (10 TO 100 BY 10);

	XAXIS LABEL = "Smoking Group"
		LABELATTRS=(Weight=Bold);

RUN;
marianhabesland
Calcite | Level 5

It actually works if I do both Group and Category. The legend at the bottom still shows up though, so will have to fix that somehow.

PeterClemmensen
Tourmaline | Level 20

Use the NOAUTOLEGEND option in the procedure statement to suppress the legend at the bottom.

 

If you want the legend somewhere else, you can control that with the KEYLEGEND Statemend.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1177 views
  • 0 likes
  • 4 in conversation