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,
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
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
You should try using SGPLOT instead. It handles time axes much better. You can specify
xaxis type=time interval=year;
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.
@ 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!
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.