Using SAS 9.3 TS Level 1M1
I have created a vbox chart in sgplot where for each year I have a boxplot of the date of conception for a sample of animals. I have set the SAS date to the same year so that I can compare month/day of conception across years. Therefore, I would only like to display day/month, or just the month, on the y axis. Below is as close as I have come. You can see on the y-axis I display month, day, and year but I only want the month displayed (or day and month).
Here is the code to generate the graph:
proc sgplot data=one noautolegend;
format conc mmddyy8.;
vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black) outlierattrs=(color=black)
;
yaxis label='Date of conception' interval=month
VALUES=("01AUG01"d "01SEP01"d "01OCT01"d "01NOV01"d "01DEC01"d "01Jan02"d "01FEB02"d "01MAR02"d)
;* valuesdisplay=("Aug" "Sep" "Oct" "Nov" "Dec" "Jan" "Feb" "Mar");
xaxis label='Year';
run;
Note that I have the "valuesdisplay" code commented out because I get an error message otherwise.
1208 valuesdisplay=("Aug" "Sep" "Oct" "Nov" "Dec" "Jan" "Feb" "Mar");
------------- -----
1 22
76
WARNING 1-322: Assuming the symbol VALUES was misspelled as valuesdisplay.
ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, (.
ERROR 76-322: Syntax error, statement will be ignored.
Is there a date format that will display only the month or month/day. Or is there some other trick with sgplot to do what I want?
Thanks!
Duane
Apply a different format and try removing the values portion entirely.
Try MONYY7 instead.
Why are you formatting conc with a date format? That doesn't make sense to me.
The variable 'conc' is the date of conception - that is what the box plot represents.
The MONYY7. format still displays the year.
Without the data I can only make suggestions.
Post your revised code.
Here's some example data included with the code.
Thanks for the suggestion about the heatmap but that is not what I need.
data one;
input year conc agename $;
cards;
1999 15265 Subadult
1999 15281 Subadult
1999 15300 Subadult
1999 15290 Subadult
2000 15284 Subadult
2000 15300 Subadult
2000 15260 Subadult
1999 15279 Adult
1999 15279 Adult
1999 15279 Adult
1999 15290 Adult
1999 15300 Adult
1999 15320 Adult
1999 15260 Adult
1999 15265 Adult
1999 15265 Adult
1999 15279 Adult
2000 15260 Adult
2000 15250 Adult
2000 15300 Adult
2000 15310 Adult
2000 15280 Adult
2000 15280 Adult
2000 15280 Adult
;
proc sgplot data=one noautolegend;
format conc monyy7.;
vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black) outlierattrs=(color=black)
;
yaxis label='Date of conception' interval=month
VALUES=("01AUG01"d "01SEP01"d "01OCT01"d "01NOV01"d "01DEC01"d "01Jan02"d "01FEB02"d "01MAR02"d)
;*valuesdisplay=("Aug" "Sep" "Oct" "Nov" "Dec" "Jan" "Feb" "Mar");
xaxis label='Year';
run;
Removing the values statement and adding the formats worked fine for me.
title 'Demo Graph';
proc sgplot data=one noautolegend;
format conc monyy7.;
vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black) outlierattrs=(color=black)
;
yaxis label='Date of conception' interval=month ;
xaxis label='Year';
run;
When I run your code the y-axis labels include the year. I just want the month.
The output I get is attached. Not sure why you're getting different output.
Can you post what you get if you run the data you provided and my code.
I get the exact same output.
On the y-axis I DO NOT want the year displayed - I only want the month.
@DuaneD wrote:
I get the exact same output.
On the y-axis I DO NOT want the year displayed - I only want the month.
Try the format MONTH. to show 1 2 3 4 etc.
MonName3. would show Jan Feb Mar
MonName8. would show the whole month name: January February etc.
Those don't seem to work. I get the following messages in the Log
2008 proc sgplot data=one noautolegend;
2009 format conc monName3.;
2010 vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black)
2010! outlierattrs=(color=black)
2011 ;
2012 yaxis label='Date of conception' ;
2013
2014 xaxis label='Year';
2015 run;
NOTE: Since no format is assigned, the numeric category variable will use the default of BEST6.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.37 seconds
cpu time 0.09 seconds
NOTE: The column format MONNAME3 is replaced by an auto-generated format on the axis.
NOTE: Listing image output written to SGPlot78.png.
NOTE: The column format MONNAME3 is replaced by an auto-generated format on the axis.
NOTE: There were 24 observations read from the data set WORK.ONE.
2016 proc sgplot data=one noautolegend;
2017 format conc month.;
2018 vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black)
2018! outlierattrs=(color=black)
2019 ;
2020 yaxis label='Date of conception' ;
2021
2022 xaxis label='Year';
2023 run;
NOTE: Since no format is assigned, the numeric category variable will use the default of BEST6.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.35 seconds
cpu time 0.12 seconds
NOTE: The column format MONTH2 is replaced by an auto-generated format on the axis.
NOTE: Listing image output written to SGPlot80.png.
NOTE: The column format MONTH2 is replaced by an auto-generated format on the axis.
NOTE: There were 24 observations read from the data set WORK.ONE.
This is the graph that I get
I suspect part of the reason with this, is the scale changes with the data so you can't really 'fix it', it's data dependent. If you did the idea of a box plot kind of goes away. I wonder if a clustered bar graph isn't more helpful here?
Regardless, I couldn't get it to work with the format approach, but I created a month variable and format and that seemed to work. I'm not sure you're going to get all months display.
data one;
input year conc agename $;
month=month(conc);
format conc monname.;
cards;
1999 15265 Subadult
1999 15281 Subadult
1999 15300 Subadult
1999 15290 Subadult
2000 15284 Subadult
2000 15300 Subadult
2000 15260 Subadult
1999 15279 Adult
1999 15279 Adult
1999 15279 Adult
1999 15290 Adult
1999 15300 Adult
1999 15320 Adult
1999 15260 Adult
1999 15265 Adult
1999 15265 Adult
1999 15279 Adult
2000 15260 Adult
2000 15250 Adult
2000 15300 Adult
2000 15310 Adult
2000 15280 Adult
2000 15280 Adult
2000 15280 Adult
;
proc format;
value monvalue
1='January'
2='February'
3='March'
4='April'
5='May'
6='June'
7='July'
8='August'
9='September'
10='October'
11='November'
12='December'
;
run;
ods graphics/ device=jpg;
title 'Demo Graph';
proc sgplot data=one noautolegend;
vbox month / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black) outlierattrs=(color=black)
;
yaxis label='Date of conception' interval=month ;
format month monvalue. ;
xaxis label='Year';
run;
Without any data it is kind of hard to test code
you may want to try:
yaxis label='Date of conception' valuesformat=Month2.;
In message 6 above I provided example code.
Interestingly, your suggestion does not work but you think it should. I get the following Log error message.
2054 proc sgplot data=one noautolegend;
2055 format conc month.;
2056 vbox conc / category=year group=agename meanattrs=(symbol=square color=black) whiskerattrs=(color=black)
2056! outlierattrs=(color=black)
2057 ;
2058 yaxis label='Date of conception' valuesformat=Month2. ;
------------ -------
1 79
76
WARNING 1-322: Assuming the symbol VALUES was misspelled as valuesformat.
ERROR 79-322: Expecting a (.
ERROR 76-322: Syntax error, statement will be ignored.
2059
2060 xaxis label='Year';
2061 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SGPLOT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.