BookmarkSubscribeRSS Feed
lone0708
Fluorite | Level 6

Hello all,

I am working with a dataset containing information about women with sample dates before, during and after last pregnancy, and i want to give them a flag describing when the sample is taken. The part teasing me is the timing between pregnancies. How can program that?

 

 

data have;

input woman  pregnancy_start  pregnancy_end sample_date;

1           01-01-2016          01-09-2016       01-01-2015     

1           01-01-2016          01-09-2016       01-01-2017     

1           01-02-2017          01-10-2017       01-01-2017    

1           01-02-2017          01-10-2017       01-01-2018    

2           01-01-2016          01-09-2016       01-05-2016    

3           01-01-2016          01-09-2016       01-01-2018     

4           01-01-2016          01-09-2016       01-01-2015

;

run;

;

run;

 

data want:

data want; 

input woman  pregnancy_start  pregnancy_end sample_date  timing;

datalines;

1           01-01-2016          01-09-2016       01-01-2015     before pregnancy

1           01-01-2016          01-09-2016       01-01-2017     between pregnancies

1           01-02-2017          01-10-2017       01-01-2017     between pregnancies

1           01-02-2017          01-10-2017       01-01-2018     after last pregnancy

2           01-01-2016          01-09-2016       01-05-2016     during pregnancy

3           01-01-2016          01-09-2016       01-01-2018     after last pregnancy

4           01-01-2016          01-09-2016       01-01-2015     before pregnancy

;

run;

 

 

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Is this a complete set of possible outcomes? Could woman 1 have a sample date during her first pregnancy? Could woman 1 have a sample date during her second pregnancy? Could woman 1 have a sample date during both pregnancies, or after both pregnancies, or before both pregnancies?

--
Paige Miller
lone0708
Fluorite | Level 6

No, you are right, all the outcomes you mention are possible outcomes. Every possible combination of samples is possible

PaigeMiller
Diamond | Level 26

So, if woman 1 had sample date during her first pregnancy, would the desired outcome be "During 1st Pregnancy"? or just "During Pregnancy"?

 

If a woman had three pregnancies, would you want "Between 2nd and 3rd Pregnancy"?

 

Don't make us guess what you want. Don't make us try to enumerate all the possible outcomes. Please give an example which illustrates all possible examples and what outcome you want.

--
Paige Miller
lone0708
Fluorite | Level 6
No, it is fine with just "during pregnancy" and "between pregnancies" 🙂
PaigeMiller
Diamond | Level 26

Example data showing all possible combinations and outcomes is requested.

--
Paige Miller
lone0708
Fluorite | Level 6

data want:

woman  pregnancy_start  pregnancy_end sample_date  timing

1           01-01-2016          01-09-2016       01-01-2015     before pregnancy

1           01-01-2016          01-09-2016       01-01-2017     between pregnancies

1           01-02-2017          01-10-2017       01-01-2017     between pregnancies

1           01-02-2017          01-10-2017       01-01-2018     after last pregnancy

2           01-01-2016          01-09-2016       01-05-2016     during pregnancy

3           01-01-2016          01-09-2016       01-01-2018     after last pregnancy

4           01-01-2016          01-09-2016       01-01-2015     before pregnancy

andreas_lds
Jade | Level 19

Please post data in usable form with all possible combinations included.

lone0708
Fluorite | Level 6
I have tried to update the post now, sorry for the in convinience

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