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;
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"?
@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.
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
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
While keeping the INTERVAL option, try the MIN and MAX options to see if they will shrink the range.
@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.
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 16. 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.