BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chris2377
Quartz | Level 8

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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

View solution in original post

4 REPLIES 4
ballardw
Super User
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

chris2377
Quartz | Level 8

Many thanks @ballardw In the meantime, I've discovered that converting years to characters also works. Just in case someone needed

ballardw
Super User

@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.

Ksharp
Super User
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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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