Data visualization with SAS programming

time x-axis not evenly spaced with major tick marks every 10 years

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

time x-axis not evenly spaced with major tick marks every 10 years

[ Edited ]

Hello,

 

I need to plot monthly market data over 100 years, with a major tick every 10 years, and no minor tick. I started with this code:

 

	axis1 order=('30Jun1930'd to '30Jun2020'd by 3640) label=(h=1.5 color=black 'Time') minor=none;
	axis2 order=(-3 to 18 by 1) label=(angle=90 h=1.5 color=black 'Cumulative wealth (log)') minor=none;

proc gplot data = Sample; plot (ln_Wealth_Portfolio ln_Wealth_Index) * Date / haxis=axis1 vaxis=axis2 legend overlay ; format Date YEAR4.; run; quit;

 

I wrote "by 3640", i.e. roughly 364*10, because I noticed that it counts in days but it is rather approximate. Would it be possible to count in years? I tried:

 

('30Jun1930'd to '30Jun2020'd by year)

with the intention to add a 10 somewhere, but it leads to the following error message:

 

WARNING: The intervals on the axis labeled "Calendar Date" are not evenly spaced.
WARNING: No minor tick marks will be drawn because major tick increments have been specified in uneven or unordered intervals.

because my dates are actually the last trading day for each month, which is not necessarily the last calendar day of the month.

Ex: 10/31/1933, 11/29/1933, 12/30/1933

with an "YYMMDD8." informat.

 

Thank you in advance for your suggestions,

 


Accepted Solutions
Solution
‎03-13-2017 02:57 PM
SAS Super FREQ
Posts: 925

Re: time x-axis not evenly spaced with major tick marks every 10 years

Try using PROC SGPLOT and see if you get a better-looking time axis:

 


proc sgplot data = Sample;
        xaxis values=('30Jun1930'd to '30Jun2020'd) label='Time';	
	yaxis values=(-3 to 18 by 1) label='Cumulative wealth (log)';
        scatter y=ln_Wealth_Portfolio x=Date;	
        scatter y=ln_Wealth_Index x=Date;
	format Date YEAR4.;
run;

You can also use the INTERVAL option on the XAXIS statement to control the time interval used onthe axis.

 

Hope this helps!

Dan

View solution in original post


All Replies
Solution
‎03-13-2017 02:57 PM
SAS Super FREQ
Posts: 925

Re: time x-axis not evenly spaced with major tick marks every 10 years

Try using PROC SGPLOT and see if you get a better-looking time axis:

 


proc sgplot data = Sample;
        xaxis values=('30Jun1930'd to '30Jun2020'd) label='Time';	
	yaxis values=(-3 to 18 by 1) label='Cumulative wealth (log)';
        scatter y=ln_Wealth_Portfolio x=Date;	
        scatter y=ln_Wealth_Index x=Date;
	format Date YEAR4.;
run;

You can also use the INTERVAL option on the XAXIS statement to control the time interval used onthe axis.

 

Hope this helps!

Dan

Respected Advisor
Posts: 4,814

Re: time x-axis not evenly spaced with major tick marks every 10 years

You should try using SGPLOT instead. It handles time axes much better. You can specify

 

xaxis type=time interval=year;

PG
Super User
Posts: 11,121

Re: time x-axis not evenly spaced with major tick marks every 10 years

When you use date values in an axis you will often get this message:

WARNING: The intervals on the axis labeled "Calendar Date" are not evenly spaced.

The number of days in months are not the same and neither are the numbers of days in a year. So the tick marks are drawn evenly spaced but the VALUES represented by the tickmarks are not. It is not an error so if the graph looks as needed then ignore it.

Contributor
Posts: 20

Re: time x-axis not evenly spaced with major tick marks every 10 years

@ DanH_sas Your code with sgplot looks nice, I will look deeper into it to customize it more. Thank you!

 

@ ballardw That's good to know, thank you for the explanation!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 338 views
  • 0 likes
  • 4 in conversation