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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 839 views
  • 0 likes
  • 3 in conversation