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

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,

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

4 REPLIES 4
DanH_sas
SAS Super FREQ

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

PGStats
Opal | Level 21

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

 

xaxis type=time interval=year;

PG
ballardw
Super User

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.

Alain38
Quartz | Level 8

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3725 views
  • 0 likes
  • 4 in conversation