BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jomag
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 610 views
  • 1 like
  • 2 in conversation