Hi!
I currently have the following variables:
All of the date variables are in days.
I used the following code to create an epicurve:
ods graphics on / scale = off;
PROC SGPLOT data = mrsa1;
vbar DILL / group = ILL;
format DILL mmddyy8.;
RUN;
ODS graphics off;
The chart I get from doing this is here:
While this works, I would prefer that my date variables were in weeks. Is there a way to change DATEdelivery into weeks and then use this in my sgplot so its not so cluttered? I would also like to stack the non cases (0) on top of the cases (1).
I have attached the dataset I am using to this as well.
Any help would be appreciated.
How do you want to display the "week" value on the xaxis?
Two basic approaches
1) create a new variable that is one day of the week for each day of the week in a data step such as:
Newdate = intnx('week', dill,0,'b');
use the same format for newdate and use newdate instead of Dill in Sgplot.
The Intnx function is the basic tool for incrementing date, time or date time values. In this case it says to use week as interval, starting with the current date Dill, adjust it 0 units to the Beginning of the week (Sunday). So the tick marks would reflect Sunday for each week.
2) Use a different format such as WeekU5. in the Sgplot. This is less intuitive to read as the value displayed will look like 21W03 (week 3 of year 2021 for example)
Hi! Thanks so much for the quick response.
This seems to be working but two things:
1) The weekly values are look like this:
2) My graph looks great but is there a way to make the 0 values on top of the 1 values? I tried a descending option, but that didnt work. Also looked on this link and couldn't find it. Right now it looks like this:
@pramenon1 wrote:
Hi! Thanks so much for the quick response.
This seems to be working but two things:
1) The weekly values are look like this:
FORMAT the variable. All dates are numeric and appear as such until you provide a FORMAT such as DATE9. to make them appear nice to humans.
2) My graph looks great but is there a way to make the 0 values on top of the 1 values? I tried a descending option, but that didnt work. Also looked on this link and couldn't find it. Right now it looks like this:
What code did you apply Descending to? If you apply it on XAXIS (the referenced link) then it affects the order of XAXIS tick values, not your group variable. So look for options related to the Group variable in the VBAR syntax.
Try
PROC SGPLOT data = mrsa1; vbar yearweek / group = ILL grouporder=descending; format yearweek mmddyy8.; RUN;
ods graphics on / scale = off;
PROC SGPLOT data = mrsa1;
vbar DILL / group = ILL groupdisplay=stack;
format DILL yyweeku8.;
RUN;
ODS graphics off;
How do you want your week displayed? You can use a format to some degree depending on what exactly you want to see.
Add
xaxis TYPE=time interval=week;
to your PROC SGPLOT staetments;
If you leave off the INTERVAL= option, the procedure will try to choose an interval that makes sense for your data. If you know that you want weeks, use INTERVAL=WEEK.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: