Help using Base SAS procedures

Top 5 values

Reply
Contributor
Posts: 69

Top 5 values

I am having a dataset with variables empcode,empname,sal,designation
I want to find out the top 5 salaries based on the designation.
Designation is a group variable.
Can anyone help me on this using datastep and proc sql;

Regards,
Siddhartha
Respected Advisor
Posts: 4,173

Re: Top 5 values

Posted in reply to Siddhartha
Searching the forums you'll find several threads dealing with this question.
Regular Contributor
Posts: 229

Re: Top 5 values

Posted in reply to Siddhartha
proc sql number outobs=5;
create table kk as
select * from sashelp.class desc group by designation order by sal descending;
quit;
Super User
Posts: 10,041

Re: Top 5 values

Hi.
Op means a group variable.(i.e. need every group's first five observations).
I have two way, one is proc ,the other is data step;

[pre]
proc sort data=sashelp.class out=class;
by sex;
run;
ods select extremeobs;
proc univariate data=class nextrobs=5;
by sex;
var weight;
run;






proc sort data=sashelp.class out=class;
by sex descending weight;
run;
data temp;
set class;
by sex;
if first.sex then id=0;
id+1;
run;
data result;
set temp;
where id in (1 2 3 4 5);
run;
proc print;
run;

[/pre]




Ksharp
Valued Guide
Posts: 634

Re: Top 5 values

Just so that you will have one more choice take a look at the IDGROUP option on the OUTPUT statement in PROC MEANS/SUMMARY.
Super User
Posts: 10,041

Re: Top 5 values

Thanks, Art Carpenter.
I will take a look.
Smiley Happy
Ask a Question
Discussion stats
  • 5 replies
  • 934 views
  • 0 likes
  • 5 in conversation