Data visualization with SAS programming

Proc SGPlot and tick marks for date values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Proc SGPlot and tick marks for date values

[ Edited ]

Please help me as these tick marks are driving me crazy!

 

I have a dataset with a sasdate variable called varDate. Every value of varDate is a date value that corresponds to the first of the month and I only have one observation per date on a monthly basis starting with april 2005, may 2005 and so on.

 

I want a major tick that starts with the value 2005 representing April 2005 and ends with 2017 but I also want minor ticks representing the months inbetween. How do I achieve this?

 

This is my code and below that the output that it produces:

 

proc sgplot data=myDatafile;
series x=varDate y=mar1 /markers markerattrs=(symbol=plus size=5);
xaxis interval=month label=' ' values=('01apr2005'd to '01SEP2017'd by 12) valuesformat=year4.;
yaxis label=' ' values=(110000 to 300000 by 20000);
run;

 

 

sgplot.png


Accepted Solutions
Solution
Monday
Super User
Posts: 11,114

Re: Proc SGPlot and tick marks for date values

values=('01apr2005'd to '01SEP2017'd by 12) is going to attempt to place a tick mark value every 12 days.

You may want to use the INTERVAL=YEAR , MINOR, to add minor tick marks, MINORCOUNT= , to specify the number of minor ticks, options instead of Values statement.

 

The version of SAS is going to limit the availability of these options though.

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 925

Re: Proc SGPlot and tick marks for date values

What version of SAS are you using?

Occasional Contributor
Posts: 5

Re: Proc SGPlot and tick marks for date values

I am using SAS 9.4 M3

Solution
Monday
Super User
Posts: 11,114

Re: Proc SGPlot and tick marks for date values

values=('01apr2005'd to '01SEP2017'd by 12) is going to attempt to place a tick mark value every 12 days.

You may want to use the INTERVAL=YEAR , MINOR, to add minor tick marks, MINORCOUNT= , to specify the number of minor ticks, options instead of Values statement.

 

The version of SAS is going to limit the availability of these options though.

 

SAS Super FREQ
Posts: 925

Re: Proc SGPlot and tick marks for date values

For this situation, you might want to use MINORINTERVAL=MONTH to make the minor ticks appear per month.

Occasional Contributor
Posts: 5

Re: Proc SGPlot and tick marks for date values

I think I did try that before and now I tried again, but it didn't do the trick. Thanks for trying!
Occasional Contributor
Posts: 5

Re: Proc SGPlot and tick marks for date values

Thank you so much for trying to help me! Your code seem to work, almost at least.

 

I have modified the original code and moved the values to a where statement. Also, I have restricted the diagram to only show the last ten years. The minor tick marks are there but there are to many of them so they really doesn't make any sense. But still I want every year to be displayed on the x-axis. Any ideas?

 

proc sgplot data=_aux_ams;
where '01SEP2007'D <= dateVar <='01SEP2017'D
series x=dateVar y=mar1 /markers markerattrs=(symbol=plus size=5);
xaxis interval=year label=' ' valuesformat=year4. minor minorcount=120;
yaxis label=' ' values=(110000 to 300000 by 20000);
run;

 

sgplot2.png

Occasional Contributor
Posts: 5

Re: Proc SGPlot and tick marks for date values

Finally, I managed to get the graph I wanted. Since I realized that the minor ticks would be far too many, I decided to not use them. By changing the xaxis interval to 'auto' and use a year-format the graph looked presentable.

 

proc sgplot data=myData;
series x=dateVar y=mar1 /markers markerattrs=(symbol=plus size=5);
xaxis interval=auto label=' ' 
values=('01SEP2007'd to '01SEP2017'd by year) valuesformat=year4.;
yaxis label=' ' values=(110000 to 300000 by 20000);
run;
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 138 views
  • 1 like
  • 3 in conversation