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;
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?
No, you are right, all the outcomes you mention are possible outcomes. Every possible combination of samples is possible
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.
Example data showing all possible combinations and outcomes is requested.
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
Please post data in usable form with all possible combinations included.
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!
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.