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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.