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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 627 views
  • 1 like
  • 2 in conversation