Data visualization with SAS programming

PROC SGPLOT

Reply
Contributor
Posts: 55

PROC SGPLOT

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

 

Super User
Posts: 13,084

Re: PROC SGPLOT

Posted in reply to marianhabesland

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.

Contributor
Posts: 55

Re: PROC SGPLOT

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

Super User
Posts: 13,084

Re: PROC SGPLOT

Posted in reply to marianhabesland

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.

Contributor
Posts: 55

Re: PROC SGPLOT

[ Edited ]

 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

 

 

Super User
Posts: 22,875

Re: PROC SGPLOT

Posted in reply to marianhabesland

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;
Contributor
Posts: 55

Re: PROC SGPLOT

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.

PROC Star
Posts: 1,193

Re: PROC SGPLOT

Posted in reply to marianhabesland

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.

Ask a Question
Discussion stats
  • 7 replies
  • 240 views
  • 0 likes
  • 4 in conversation