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;