BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
drshashlik
Fluorite | Level 6

Hi,

I have hospital admissions data for a cohort of children.  Some children have only one admission, while others have many.  Each admission is a new row.  So I can have multiple rows for each child, and each row is a new hospital admission.

I want to count the days between each admission for each child.  

I'm using SAS9.4 1M5

Many thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

A very important question: is the admission date a SAS date valued variable, meaning numeric with a format like DATE9. or MMDDYY10. or similar applied to it?

If not then we need to know exactly how your date values are stored as that seriously affects the next steps.

And is the value actually a date or does it have a time component as well? Some folks seem not to know the difference and we get questions about "dates" like 01JAN2020:17:23:15, which has TIME and different approach would be needed.

 

If the date variable is a SAS date value then something like:

Proc sort data=have;
   by childid date;
run;

data want; 
   set have;
   by childid;
   days= dif(date);
   if first.childid then days = 0;
run;

Days will have the number days between visits for those children with multiple visits and with 0 for the first visit by any child.

View solution in original post

3 REPLIES 3
geoskiad
Fluorite | Level 6
Hi,

You are not really clear about your variables and the structure of the data but I would guess you have some kind of admission date. Try using LAG function per subject and then calculate the difference of days between the 2 dates (the normal one and the newly created lag one).
ballardw
Super User

A very important question: is the admission date a SAS date valued variable, meaning numeric with a format like DATE9. or MMDDYY10. or similar applied to it?

If not then we need to know exactly how your date values are stored as that seriously affects the next steps.

And is the value actually a date or does it have a time component as well? Some folks seem not to know the difference and we get questions about "dates" like 01JAN2020:17:23:15, which has TIME and different approach would be needed.

 

If the date variable is a SAS date value then something like:

Proc sort data=have;
   by childid date;
run;

data want; 
   set have;
   by childid;
   days= dif(date);
   if first.childid then days = 0;
run;

Days will have the number days between visits for those children with multiple visits and with 0 for the first visit by any child.

drshashlik
Fluorite | Level 6

thanks Ballardw,

date is DDMMYY10.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 3 replies
  • 783 views
  • 0 likes
  • 3 in conversation