Hello All,
I have a longitudinal data set and I am interested to know how many children (<18 years of age) transition to adulthood (18 years and older) during the study period. Furthermore, I would like to create a binary variable that denotes if a child transitioned to adulthood and use that variable for further analyses. Please see the set up of data in the excerpt below. Any suggestions to easily create the transition binary variable will be greatly appreciated.
I tried:
data age_first;
set age_tran;
if first.studyid;
by studyid;
if age < 18 then Age_first = 1;
else age_first = 0;
keep studyid age age_first;
run;
data age_last;
set age_tran;
if last.studyid;
by studyid;
if age >= 18 then Age_last = 1;
else Age_last = 0;
keep studyid age age_last;
run;
data age_trans;
merge age_first (in=a) age_last (in=b);
by studyid;
Add_age = age_first + age_last;
if add_age >1 then age_trans = 1;
if add_age <= 1 then age_trans = 0;
run;
This worked but felt like it was too long a process and I am wondering if there is an efficient way to code than what I followed.
Thank you for your time.
will this help?
data age_tran;
input StudyID Age;
cards;
1 14
1 15
1 17
1 18
1 19
1 19
1 19
1 19
1 19
2 23
2 23
2 26
2 26
2 26
3 18
3 18
3 19
3 19
;
data age_trans;
set age_tran;
by studyid;
retain Age_first;
if first.studyid or last.studyid ;
if first.studyid then Age_first=age < 18;
else if last.studyid then Age_last=age >= 18;
if last.studyid ;
Add_age = age_first + age_last;
age_trans=add_age >1;
run;
will this help?
data age_tran;
input StudyID Age;
cards;
1 14
1 15
1 17
1 18
1 19
1 19
1 19
1 19
1 19
2 23
2 23
2 26
2 26
2 26
3 18
3 18
3 19
3 19
;
data age_trans;
set age_tran;
by studyid;
retain Age_first;
if first.studyid or last.studyid ;
if first.studyid then Age_first=age < 18;
else if last.studyid then Age_last=age >= 18;
if last.studyid ;
Add_age = age_first + age_last;
age_trans=add_age >1;
run;
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.