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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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