Data visualization with SAS programming

Formatting of x-axis labels

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Formatting of x-axis labels

[ Edited ]

Hi all,

 

I need some help while creating the graph plots. I am using the following code. 

 

ods graphics on / width=8in height=6in outputfmt=gif imagemap=on border=off;

title1 "SGPLOT Output for &name.";

proc sgplot data=out_ds ;

           series x=quarter y=default_flag/ legendlabel="Default Rate" markers lineattrs=(thickness=2);

           series x=quarter y=Varname/y2axis legendlabel="Unemployment rate" markers lineattrs=(thickness=2);

           xaxis type=discrete display=(noline noticks) grid  label="Time Period";

           yaxis display=(noline) grid  label="Default Rate" ;

           y2axis label="Unemployment rate";

run;

 

The x-axis "quarter" contains the values 2001Q1, 2001Q2, 2001Q3, 2001Q4, 2002Q1..... so on

My input data contains values from 1995Q1 to 2020Q4. So the values of x-axis labels in the graph are coming too close. Since this is character values, I am not able to use values= option.

Is there any way , I can get skip quarters and print only years (with four ticks for each quarter). 

Or any other easy way so that the labels are not too close.

 

Thanks

 


Accepted Solutions
Solution
‎12-12-2017 01:12 AM
SAS Super FREQ
Posts: 1,042

Re: Formatting of x-axis labels

Posted in reply to UshaLatha

Your best option here is to use a data step to create a temporary data set that uses an informat on your "quarter" column to turn it into a true datetime value. Then, assign a YYQ. format to that column and let SGPLOT create a time axis for you on the X axis (remove the type=discrete). You might also need to set INTERVAL=QUARTER on that axis statement to get what you want.

 

Hope this helps!

Dan

 

View solution in original post


All Replies
Solution
‎12-12-2017 01:12 AM
SAS Super FREQ
Posts: 1,042

Re: Formatting of x-axis labels

Posted in reply to UshaLatha

Your best option here is to use a data step to create a temporary data set that uses an informat on your "quarter" column to turn it into a true datetime value. Then, assign a YYQ. format to that column and let SGPLOT create a time axis for you on the X axis (remove the type=discrete). You might also need to set INTERVAL=QUARTER on that axis statement to get what you want.

 

Hope this helps!

Dan

 

Contributor
Posts: 28

Re: Formatting of x-axis labels

Thanks Dan !! this works perfectly..

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 143 views
  • 1 like
  • 2 in conversation