Hi,
I am outputting a graph for reporting and just recently changed the x-axis to a new variable. The issue I am running into is when the graph is generated, the x-axis looks very cluttered. How do I decrease tick marks without taking out the actual values?
Code used to generate graph (Please note that x-axis is a character variable):
PROC SGPLOT DATA = freqweek&today. ;
SERIES X = yr_week Y = PCT_COL;
where def=1 & yr_week gt '2022wk01' & yr_week lt '2023wk02';
yaxis label='Placeholder' values=(0.0 to 100.0 by 10);
xaxis label='Placeholder';
TITLE 'Placeholder';
RUN;
What is being outputted:
Assign format YYWEEKW7. (or whatever number you want) to variable ADMITDATE, and then plot ADMITDATE
Your variable named YR_WEEK is obviously a character variable, and it has lots of values, and so each one is plotted.
What you really want is a variable that is numeric — all dates in SAS should be (I would say MUST be) numeric, and dates in SAS are the number of days since 01JAN1960, formatted to be readable. So convert your dates to a SAS numeric variable, format it any way you want, and then the numeric variable ought to plot in a more reasonable way.
How did you create these text strings for YEAR_WK? If we knew that, we could provide code to create a numeric date value in a new variable that will plot properly.
The issue is that I have been asked to report by week, and I was using the weekw5. format, but after the new year, it was not capturing the full week due to the year change. The yr_week variable captures the week starting on Sunday through the following Saturday.
Yr_week was created using this code:
yr_week=cats(year(admitdate), "wk", put(week(admitdate),z2.));
Assign format YYWEEKW7. (or whatever number you want) to variable ADMITDATE, and then plot ADMITDATE
PROC SGPLOT DATA = freqweek&today. ; SERIES X = admit_date Y = PCT_COL; where def=1 & admit_date gt '01Jan2022'd & admit_date lt '14Jan2023'd; yaxis label='Placeholder' values=(0.0 to 100.0 by 10); xaxis label='Placeholder' values = ('01Jan2022'd to '14Jan2023'd by 14) valuesformat= yyweekw7.; TITLE 'Placeholder'; RUN;
Something like above. You may need to adjust your dates to get it exactly as desired.
@scolitti1 wrote:
The issue is that I have been asked to report by week, and I was using the weekw5. format, but after the new year, it was not capturing the full week due to the year change. The yr_week variable captures the week starting on Sunday through the following Saturday.
Yr_week was created using this code:
yr_week=cats(year(admitdate), "wk", put(week(admitdate),z2.));
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.