BookmarkSubscribeRSS Feed
☑ This topic is solved. 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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 542 views
  • 0 likes
  • 3 in conversation