Hi all I am bumping into a coding issue that has me stumped. I have 5 years of data for a children under 5 and I need to find for each year the number that turned specific ages who breastfed for specific time periods in a year. For example, I need to calculate all of the children who turned 1+ weeks old in the year who breastfed for more than one week, children who turned 2+ weeks old in the year who breastfed for more than two weeks, etc. I have child DOB, date last asked about breastfeeding and whether they ever breastfed. I have sorted out how ages at the beginning and end of the time period and age at time of breastfeeding question but I keep ending up with too many kids in each age group, probably because I am pulling in everyone who was 1+weeks, 2+weeks, etc. old, rather than just those who turned that age during the time period. I am stumped on how to get only the kids that turned that age in the year, especially since kids pass from one age group to the next through out the year. So your 1 week olds become 2 weeks, become 3 weeks....up to 18 months. Any help would be greatly appreciated! A portion of my code is below Thanks, Erica data BFDuration; set perm.dataset; IF AGEMOS<60 AND AGEMOS NE .; %LET YR=YEAR; Startperiod = MDY(1,1,&yr); Endperiod = MDY(12,31,&yr); *****Child birthday******; child_dobmo= substr(child_dob,1,2); child_dobdy= substr(child_dob,3,2); child_dobyr= substr(child_dob,5,4); ChildDOB = MDY(child_dobmo, child_dobdy, child_dobyr); *********Last breastfeeding response***** lstbrstfeddt_mo= substr(lstbrstfed_dt,1,2); lstbrstfeddt_dy= substr(lstbrstfed_dt,3,2); lstbrstfeddt_yr= substr(lstbrstfed_dt,5,4); DOBreastfed = MDY(lstbrstfeddt_mo ,lstbrstfeddt_dy ,lstbrstfeddt_yr); *****Age at last breastfeeding response in weeks and months**** BFAGEwk=INTCK('WEEK',CHILDDOB,DOBREASTFED); BFAGEmo=INTCK('MONTH',CHILDDOB,DOBREASTFED); ****Currently or ever breastfed***** if cur_brstfed='1' or ever_brstfed='1' then brstfed='1'; if cur_brstfed='2' and ever_brstfed='2' then brstfed='2'; if cur_brstfed~='' and ever_brstfed='' then brstfed=cur_brstfed; if cur_brstfed='' and ever_brstfed~='' then brstfed=ever_brstfed; *****Age at beginning and end of time period***** if childdob<= MDY(1,1,&yr) then DO; AGESTARTwk=intck('WEEK',childdob,Startperiod); AGESTARTmo=intck('MONTH',childdob,Startperiod); AGEENDwk=intck('WEEK',childdob,Endperiod); AGEENDmo=intck('MONTH',childdob,Endperiod) END; if childdob> MDY(1,1,&yr)then DO; AGEENDwk=intck('WEEK',childdob,Endperiod); AGEENDmo=intck('MONTH',childdob,Endperiod); END; IF AGESTARTwk<=1 AND AGESTARTwk NE . AND brstfed=1 THEN DO; IF BFAGEwk>=1 THEN BF1WK=1; IF BFAGEwk<=1 THEN BF1WK=0; END; IF AGEENDwk>1 AND AGEENDWK NE . AND brstfed=1 THEN DO; WEEK1=INTCK('WEEK',CHILDDOB,DOBreastfed); IF BFAGEwk>=1 THEN BF1WK=1; IF BFAGEwk<=1 THEN BF1WK=0; END; IF brstfed=2 THEN DO; BF1WK=0; END;
... View more