Hi fellow SAS users,
I kindly need your help.
I have a data set as follows ( attached.)
I’d like to count the number of drugs B ( NOT drug A!) taken by the mother BETWEEN pregnancy_start date and pregnancy_end date.
Note: Some drugs B were taken before pregnancy started and count should NOT be initiated on that.
Once the count has been done, I’d like to collapse the table in a way that it is one row per child ( as child is UNIT of analysis) and the column for count should have the last (total) count.
Thanking you all in anticipation.
data count_drug_B;
input child_id $ mother_id $ pregnancy_start: date9. prescriptiondate: date9. drug $;
format pregnancy_start preg_end_proxy prescriptiondate date9.;
month= intck('month',pregnancy_start, prescriptiondate);
preg_end_proxy= intnx('month', pregnancy_start,'9');
datalines;
01 001 12feb2005 10mar2004 A
01 001 12feb2005 11apr2005 A
01 001 12feb2005 13jul2005 B
02 001 18jun2006 25jul2006 B
02 001 18jun2006 12aug2006 A
02 001 18jun2006 10OCT2006 B
02 001 18jun2006 11nov2006 B
02 001 18jun2006 12dec2006 B
03 002 10oct2006 11nov2006 A
03 002 10oct2006 18dec2006 B
03 002 10oct2006 15jan2007 B
04 003 14feb2005 10mar2005 A
04 003 14feb2005 11apr2005 A
04 003 14feb2005 13jul2008 B
05 004 18jun2006 25jul2005 B
05 004 18jun2006 12aug2006 B
05 004 18jun2006 10OCT2006 A
05 004 18jun2006 11nov2006 A
05 004 18jun2006 12dec2008 B
06 005 10oct2006 11nov2006 A
06 005 10oct2006 18dec2006 B
06 005 10oct2006 15jan2007 A
;
How do you know that the drug had been taken continuously?
What would be the count for below? Just count of days since the first prescription until the end of the pregnancy? Or some other logic?
"number of drug B from the pregnancy start date to pregnancy end date"
Please don't repeat your statement but answer the question. What is the logic to derive this number? Count of days since first dispense date until end of pregnancy? Or something else?
I would like to know the total number of drugs B consumed between pregnancy start and pregnancy end date.
By using the statement
preg_end_proxy= intnx('month', pregnancy_start,'9');
you are NOT simulating a 9 month pregnancy. You are likely generating an average of 8.5 months, which of course can influence your count of B drugs during pregnancy.
That's because all your pregnancy end dates are aligned to the beginning of the month, by default of the INTNX function.. I.e. a pregnancy that starts on 1/1/2021 will have a preg_end_proxy value of 10/1/2021, which is fine. But a pregnancy that starts 30 days later, on 1/31/2021, will also have a preg_end_proxy value of 10/1/2021 - effectively 8 months. That is definitely NOT fine.
BTW, change your character literal '9' to a numeric literal 9, to avoid an unneccessary "Character values have been converted to numeric values ..." note.
I'd suggest using a 40 week interval. Also include the 'S' (for same day-of-week) argument, to prevent INTNX from aligning preg_end_proxy to the beginning of the week:
preg_end_proxy= intnx('week', pregnancy_start,40,'s');
or you could just use 280 days:
preg_end_proxy= pregnancy_start + 280;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.