proc sql outobs=5;
select age from sashelp.class;
group by age;
order by age desc;
quit;
Top N Values how to get
Hello,
Your SQL code is only one instruction so you only need a semi-colon at the end.
You also need to add the DISTINCT keyword.
proc sql outobs=5;
select distinct age from sashelp.class
order by age desc;
quit;
EDIT: removed group by.
Sort by descending and take the first N values of that.
proc sort data = sashelp.class out = temp; by descending age; run; data want; set temp (keep = age obs = 5); run;
@BrahmanandaRao wrote:
i am not getting ouput
Please post the code you use and the complete log. Both as text!
Hello,
Your SQL code is only one instruction so you only need a semi-colon at the end.
You also need to add the DISTINCT keyword.
proc sql outobs=5;
select distinct age from sashelp.class
order by age desc;
quit;
EDIT: removed group by.
In addition the solutions given, you might also want to learn how to create a table and bar chart of the Top N values by using PROC FREQ: How to create a "Top 10" table and bar chart.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.