BookmarkSubscribeRSS Feed
usuario_estudo
Calcite | Level 5

I want to change this code that will fill a variable with the ID corresponding to a minimum age. Because in case we have more than one ID with the same minimum age, I would like to bring the minimum ID (containing the minimum age) for the variable ID_AGE_MIN.

proc sql;
   create table want as
   select *, (select id from have having min(age)=age) as id_min_age
   from have;
quit;
3 REPLIES 3
usuario_estudo
Calcite | Level 5

I want to change this code that will fill a variable with the ID corresponding to a minimum age. Because in case we have more than one ID with the same minimum age, I would like to bring the minimum ID (containing the minimum age) for the variable ID_AGE_MIN.

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

 

Astounding
PROC Star

Since we don't have a data set to work with, this is untested code.  You'll need to test it to see how close it comes to answering your question.

 

proc sort data=have;
   by age ID;
run;

data want;
   set have;
   if _n_=1 then id_age_min = id;
   retain id_age_min;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1194 views
  • 0 likes
  • 3 in conversation