Hi,
I'm trying to plot highlow chart using sgplot with the code below. How to make SAS show all years on the x-axis? Currently it shows only even numbers. I've tried different xaxis options but without success.
data have;
input year min max;
datalines;
2015 10 20
2016 15 25
2017 20 30
2018 25 50
2019 40 45
2020 20 50
2021 10 80
;
run;
proc sgplot data=have noborder;
highlow x=year low=min high=max / type=bar;
run;
proc sgplot data=have noborder; highlow x=year low=min high=max / type=bar; xaxis values=(2015 to 2021 by 1); run;
Or an explicit list of values
proc sgplot data=have noborder; highlow x=year low=min high=max / type=bar; xaxis values=(2015 to 2021 by 1); run;
Or an explicit list of values
Many thanks @ballardw In the meantime, I've discovered that converting years to characters also works. Just in case someone needed
@chris2377 wrote:
Many thanks @ballardw In the meantime, I've discovered that converting years to characters also works. Just in case someone needed
I find the flexibility of the Values = (x to y by z) to be much more flexible than character. Also if your graph size and number of X axis values is "large" then you can have much more control easily than with character values.
You want to use extreme caution with character values for date related issues, especially for those still unenlightened enough to use 2-digit years for any purpose. Display order can be other than expected (99 is way after 01 with 2 digits). Four digit years are generally not a problem but as soon as you move this to DATES you can have issues with too many values and hard to read graphs and/or sort order.
And if character values are used then some plots like Reg don't really work as that requires an actual calculated interval.
data have;
input year min max;
datalines;
2015 10 20
2016 15 25
2017 20 30
2018 25 50
2019 40 45
2020 20 50
2021 10 80
;
run;
proc sgplot data=have noborder;
highlow x=year low=min high=max / type=bar;
xaxis type=discrete;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.