BookmarkSubscribeRSS Feed
dtc00011
Calcite | Level 5

Hello,

 

I am a novice to intermediate user and not super great with dates in SAS. I have a dataset where we have gestational age of an infant in weeks such as 38.20 and the infants date of birth. Essentially I need to figure out from DOB backwards using gestational age to determine a sort of proxy for the entire time period of pregnancy. I need to have a list of each day of pregnancy by date, this is to determine sort of a window of time where they could have an adverse exposure during pregnancy. This found date range will be used to inform if an exposure by specific dates occurred during the course of their pregnancy.

 

Like I said, I am not great with SAS dates and am a bit rusty and not sure where to start. I have been trying to google things but it is not giving me what I need because I am trying to find the best words to describe what I am attempting to do. Please let me know I would greatly appreciate anyone's help!


Thanks!

3 REPLIES 3
Patrick
Opal | Level 21

Not sure but are you after something like below?

data have;
  input gestational_age dob : mmddyy10.;
  format dob date9.;
  datalines;
38.20 01/15/2024
; 
run;

/* Step 2: Calculate the estimated conception date */
data want;
  set have;
  conception_date = floor(dob -gestational_age*7);
  do pregnancy_dates=conception_date to dob;
    output;
  end;
  format conception_date pregnancy_dates date9.;
/*  format dob conception_date pregnancy_dates best32.;*/
run;

proc print data=want;
run;

 

dtc00011
Calcite | Level 5
Hello! This looks like what I could be looking for! I will attempt to use this and let you know if it worked! Thank you so much!!!
Sarath_A_SAS
Obsidian | Level 7

data pregnancy_dates;
set your_dataset;

/* Convert gestational age from weeks to days */
gestation_days = gestational_age * 7;

/* Calculate the estimated date of conception */
conception_date = dob - gestation_days;

format conception_date dob date9.;
run;

data pregnancy_days;
set pregnancy_dates;

/* Initialize the start date */
start_date = conception_date;

/* Loop to generate each day in the pregnancy period */
do pregnancy_date = start_date to dob;
output;
end;

format pregnancy_date date9.;
run;

 

If you also have a dataset with specific exposure dates, you can compare those dates with the generated pregnancy dates to see if any exposures occurred during the pregnancy:

 

proc sql;
create table exposures_during_pregnancy as
select a.*, b.exposure_date
from pregnancy_days as a
left join exposure_data as b
on a.pregnancy_date = b.exposure_date
where b.exposure_date is not null;
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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