Obsidian | Level 7

## calculate weeks between a date and numeric variable

I'm working on a birth cohort analysis of a 20 year administrative dataset with moms and babies. I'm attempting to do something easy, but cannot figure out how to define weeks of pregnancy to identify trimester 1, trimester 2, and trimester 3 critical windows of susceptibility. I do not have estimated last menstrual period, but only admission_date (date of hospital delivery) and numeric variable for gestation_weeks (20 weeks to 44weeks). How do I work backwards to subtract admission_date from gestation_weeks to then use to define trimester divisions: 1-13 weeks (trimester 1); 14-26 weeks (trimester 2); and >= 27 weeks (trimester 3)?

1 ACCEPTED SOLUTION

Accepted Solutions
PROC Star

## Re: calculate weeks between a date and numeric variable

Here's something to get started with:

data _null_;
gestation_weeks = 44;
conception_date = intnx('WEEK', admission_date, -gestation_weeks, 'B');
put _all_;
run;

I've defined a conception date, then you can use INTNX again to get trimesters.

4 REPLIES 4
PROC Star

## Re: calculate weeks between a date and numeric variable

Here's something to get started with:

data _null_;
gestation_weeks = 44;
conception_date = intnx('WEEK', admission_date, -gestation_weeks, 'B');
put _all_;
run;

I've defined a conception date, then you can use INTNX again to get trimesters.

Diamond | Level 26

## Re: calculate weeks between a date and numeric variable

In addition using INTNX as above, you could also compute dates like this:

end_of_trimester1 = conception_date + 7*13;

--
Paige Miller
Obsidian | Level 7

## Re: calculate weeks between a date and numeric variable

This is very helpful! And helps me get all the way through the calculation. With sincere gratitude!

Obsidian | Level 7

## Re: calculate weeks between a date and numeric variable

This worked!!! So, so grateful to SASKiwi for helping me think through this. I was close, just couldn't get there on my own.

Discussion stats
• 4 replies
• 777 views
• 2 likes
• 3 in conversation