BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

I am trying to produce a line graph. I have set up y axis properly but x axis (i.e. dates from 9/1/2020 through 12/1/2022) - i would like graph to show every 3 months so that the graph isn't too busy. I tried "endpoints"  for xaxis values but it wont' produce what I need

 

PROC SGPLOT DATA = data;
SERIES X = month_year Y = cumulative_enroll /markers lineattrs=(thickness=2) markerattrs=(symbol=circle);
YAXIS VALUES=(0 to 1500 by 300);
XAXIS TYPE = DISCRETE;
LABEL cumulative_enroll = "Cumulative Enrollment" ;
LABEL month_year = "Month/Year" ;
xaxis valueattrs=(size=10pt color=black);
yaxis valueattrs=(size=10pt color=black);
RUN;

6 REPLIES 6
PaigeMiller
Diamond | Level 26

It's really hard to suggest a solution without seeing (a portion of) the data, and also the plot that does come out. Please provide (a portion of) the data according to these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

Please show us a screen capture of the plot that is produced, and include it in your reply by clicking on the "Insert Photos" icon.

 

Also, did you really mean to place this question under "SAS Visual Analytics"?

--
Paige Miller
ballardw
Super User

@monday89 wrote:

I am trying to produce a line graph. I have set up y axis properly but x axis (i.e. dates from 9/1/2020 through 12/1/2022) - i would like graph to show every 3 months so that the graph isn't too busy. I tried "endpoints"  for xaxis values but it wont' produce what I need

 

PROC SGPLOT DATA = data;
SERIES X = month_year Y = cumulative_enroll /markers lineattrs=(thickness=2) markerattrs=(symbol=circle);
YAXIS VALUES=(0 to 1500 by 300);
XAXIS TYPE = DISCRETE;
LABEL cumulative_enroll = "Cumulative Enrollment" ;
LABEL month_year = "Month/Year" ;
xaxis valueattrs=(size=10pt color=black);
yaxis valueattrs=(size=10pt color=black);
RUN;


IF, and this seems to be a big if for some folks, your X-axis variable is a SAS date value you could add:

 

values = ( '01SEP2020'd to d01DEC2022'd by quarter)

to the XAXIS statement.

You might want to assign a format that reflects as quarter to the variable for the procedure to show quarter labels for the tickmarks.

 

The form of 'ddMONyyyy'd , Date9. or Date7. format in quotes followed by d without a space, is the only way to show a date literal value.  The BY intervals in the values statement could be week, month, quarter year and probably a few others but those are most common for dates.

 

You may want to consider making sure your XAXIS statement is a single statement. There are some statements that when multiple statements are used only one gets applied and it can be hard sometimes to find that particular issue. Also having all of the options together makes it easier when you modify something to identify related issues you may want to change, such as fewer tickmarks you might want larger text or a different VALUESFORMAT applied.

DanH_sas
SAS Super FREQ

Instead of setting TYPE=DISCRETE on the X axis, set INTERVAL=QUARTER. This assumes that your data has some kind of data/time format.

 

Hope this helps!

Dan

monday89
Fluorite | Level 6

Thank you that worked! 

 

One following question - the graph should start with 9/1/2020 but when i added "interval = quarter", it changed to "7/1/2020" as a starting point

 

DanH_sas
SAS Super FREQ

While keeping the INTERVAL option, try the MIN and MAX options to see if they will shrink the range.

ballardw
Super User

@monday89 wrote:

Thank you that worked! 

 

One following question - the graph should start with 9/1/2020 but when i added "interval = quarter", it changed to "7/1/2020" as a starting point

 


7/1/2020 is the first month of the third calendar quarter. So likely the interval picked that to display and not 9/2/2020 which would be the last month of the third calendar quarter.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 448 views
  • 2 likes
  • 4 in conversation