BookmarkSubscribeRSS Feed
pramenon1
Obsidian | Level 7

Hi!

 

I currently have the following variables:

  • N1 (patient ID)
  • DATEdelivery (date baby was born)
  • ILL (whether baby was ill or not [0 = no, 1 = yes].
  • DILL (date the baby become ill)

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:curve.PNG

 

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.

8 REPLIES 8
ballardw
Super User

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)

pramenon1
Obsidian | Level 7

Hi! Thanks so much for the quick response.

This seems to be working but two things:

1) The weekly values are look like this:

yaer.PNG

 

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:

 

new curve.PNG

ballardw
Super User

@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:

yaer.PNG

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:

 

new curve.PNG


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;
Reeza
Super User
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. 

 

  • YYWEEKU format will display dates as 2007-W01
  • GROUPDISPLAY = STACK will stack the bar instead of clustering them

 

pramenon1
Obsidian | Level 7
Is there a way to make it so that my cases are below my noncases?
Reeza
Super User
Did you try sorting your data first?
pramenon1
Obsidian | Level 7
I did! Do I need to add a order = data to the sgplot?

PROC SORT data = mrsadates; by descending ILL; RUN;
ods graphics on / width = 8in height = 5in;
PROC SGPLOT data = mrsadates;
styleattrs DATACOLORS=(blue red);
vbar DATEDelivery / group = ILL groupdisplay = stack transparency = .5;
format DATEDelivery yyweeku8.;
RUN;
ODS graphics off;
Rick_SAS
SAS Super FREQ

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 8 replies
  • 1203 views
  • 6 likes
  • 4 in conversation