Hello SAS Communities,
I am working with a data set that is analysing diastolic blood pressure in different categories of ethnicity and race. I am wanting to create a Box Plot with PROC SGPLOT that displays Ethnicity on the X-axis and the diastolic blood pressure values on the Y-axis. I have been able to create a plot with all specifications that I desire, except the values and labels for the X-axis. These values do not display in the final output.
My Question: How do I get the x-axis values to display? Why are they not displaying?
Here is the code that I have currently written in efforts to generate my plot. I have also included the current output that I am receiving from this code.
Thank you very much for all of your help in advance.
- James
Best practice is to show the code from the log with all warnings and notes. Copy the entire procedure or data step code with the notes. Then Paste into a code box opened with the </> icon. This will preserve formatting of any diagnostic characters or text SAS provides some errors.
This also show us exactly the code that was submitted. Entirely too many times people edit the code and do not show what was actually submitted.
The XAXIS statement would need a space before the VALUES option and would typically generate an ERROR as in this example:
151 proc sgplot data=sashelp.class; 152 scatter x=height y=weight; 153 xaxisvalues= (25 to 150 by 25); ------------ 1 22 76 WARNING 1-322: Assuming the symbol XAXIS was misspelled as xaxisvalues. ERROR 22-322: Syntax error, expecting one of the following: RANGES, VALUES. ERROR 76-322: Syntax error, statement will be ignored. 154 run;
See how the xaxisvalues is underlined? See the ERROR?
So likely you are posting the result of different code than you show.
@JamesPatton01 wrote:
Hello SAS Communities,
I am working with a data set that is analysing diastolic blood pressure (DBP) in different categories of ethnicity and race (EthRaceCd). I am wanting to create a Box Plot with PROC SGPLOT that displays Ethnicity/Race Code on the X-axis and the DBP values on the Y-axis. I have been able to create a plot with all specifications that I desire, except the values and labels for the X-axis. These values do not display in the final output.
My Question: How do I get the x-axis values to display? Why are they not displaying?
For additional context, I am wanting to display character values on the X-axis that correspond to each box plot that are as follows from left to right where NH stands for Non-Hispanic:
Hispanic, NH Asian, NH Black, NH Other Race, NH White
The first 10 observations of the dataset that I am working with are displayed below for reference. I have also attached this data file.
Here is the code that I have currently written in efforts to generate my plot. I have also included the current output that I am receiving from this code.
TITLE1 "Diastolic Blood Pressure by Ethnicity/Race Code";PROC SGPLOT DATA = HypAnl.HypAnalysis1 NOAUTOLEGEND;VBOXDBP/GROUP = EthRaceCdFILLATTRS= (COLOR = LIGHTRED)LINEATTRS= (PATTERN = SOLID)WHISKERATTRS= (COLOR = BLACK) ;STYLEATTRSDATACONTRASTCOLORS= ( BLACK );STYLEATTRS DATASYMBOLS= (DIAMOND);REFLINE 90/AXIS=YLINEATTRS=(COLOR=RED)LABEL='Hypertension Threshold'LABELLOC= INSIDELABELPOS= MIN;XAXISVALUES= ( 'Hispanic' 'NH Asian' 'NH Black' 'NH Other Race' 'NH White' )OFFSETMIN= 0.2OFFSETMAX = 0.2LABEL= 'Ethnicity/Race Group'LABELATTRS= (WEIGHT= BOLD);YAXISVALUES= (0 10 20 30 40 50 60 70 80 90 100 )OFFSETMIN= 0LABEL= 'Latest DBP Meeasurement'GRIDLABELATTRS= (WEIGHT= BOLD);INSET'HypAnl.HypAnalysis1 (As of December 31, 2014)'/POSITION= BOTTOMRIGHTBORDERTITLE = 'Data Source:'TITLEATTRS= (SIZE= 9 PTWEIGHT= BOLD)TEXTATTRS= (SIZE= 8 PTSTYLE= ITALIC);RUN;![]()
Thank you very much for all of your help in advance.
- James
Hello!
Have you tried using CATEGORY = EthRaceCd rather than GROUP = EthRaceCd? By using CATEGORY = your box plots should be organized by the discrete variables Hispanic, NH Asian, NH Black, NH Other Race, NH White. I would also recommend commenting out VALUES= ( 'Hispanic' 'NH Asian' 'NH Black' 'NH Other Race' 'NH White' ) as that should not be necessary.
I agree with what was mentioned, change group to category like this: VBOX DBP / Category = EthRaceCd, then remove the line that states XAXISVALUES= ( 'Hispanic' 'NH Asian' 'NH Black' 'NH Other Race' 'NH White' ) so it says XAXIS OFFSETMIN = 0.1
LABEL = 'Ethnicity/Race Group'
LABELATTRS = ( WEIGHT = BOLD )
;
then add a format at the end to change the axis name FORMAT EthRaceCd $EthRaceCd.;
Hope that helps,
Neeloo
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.