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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

2 REPLIES 2
DanH_sas
SAS Super FREQ

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

 

UshaLatha
Obsidian | Level 7

Thanks Dan !! this works perfectly..

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 3194 views
  • 1 like
  • 2 in conversation