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