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

I would like to create a code that fill in a variable with the value which is the id corresponding to a minimum age. In case you have more than one ID with the same minimum age, Iwould like to bring the smallest ID (containing the smallest age) for the variable ID_AGE_MIN, e.g:

 

ID AGE ID_MIN_AGE

1133
2253
373
473
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Perhaps

 

data have;
input ID AGE;
datalines;
1	13
2	25
3	7 
;

proc sql;
   create table want as
   select *, (select id from have having min(age)=age) as id_min_age
   from have;
quit;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Perhaps

 

data have;
input ID AGE;
datalines;
1	13
2	25
3	7 
;

proc sql;
   create table want as
   select *, (select id from have having min(age)=age) as id_min_age
   from have;
quit;
usuario_estudo
Calcite | Level 5
It's perfect.
I just had one problem:
In case you have more than one ID with the same minimum age. In this case, I would like to bring the smallest ID (containing the smallest age) for the variable ID_AGE_MIN.