Hi,
I wanted to find name of whose age is mininum in the sashelp.class dataset using proc sql.
I'm trying using below.
proc sql;
create table want as
select min(age), name from sashelp.class;
quit;
but is giving all 19 records with min 11 age on all records.
I want record/s with minimum age and their name.
In this case.. 11th and 18th records in class dataset having age is 11, which is minimum .
Please help.
The reason your query returned 19 rows because you selected min (age) for each name. Hence the result.
Hope that explains.
Good Luck...!!!
One of the way is to use subquery in SQL
proc sql;
select
a.name,
a.age
from sashelp.class as a
where a.age in
(select min(age) from sashelp.class )
;
quit;
Try this:
proc sql;
create table want as
select name , age
from sashelp.class
where age in (select min(age)
from sashelp.class);
quit;
It gives 2 rows as they both have age 11 which is the least.
Name Age
1 Joyce 11
2 Thomas 11
The reason your query returned 19 rows because you selected min (age) for each name. Hence the result.
Hope that explains.
Good Luck...!!!
proc sql;
select *
from sashelp.class
having min(age)=age
;
quit;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.