Fluorite | Level 6

## How to count days between multiple admissions

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

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How to count days between multiple admissions

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.

3 REPLIES 3
Fluorite | Level 6

## Re: How to count days between multiple admissions

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).
Super User

## Re: How to count days between multiple admissions

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.

Fluorite | Level 6

## Re: How to count days between multiple admissions

thanks Ballardw,

date is DDMMYY10.

Discussion stats
• 3 replies
• 729 views
• 0 likes
• 3 in conversation