BookmarkSubscribeRSS Feed
Siddhartha
Calcite | Level 5
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
5 REPLIES 5
Patrick
Opal | Level 21
Searching the forums you'll find several threads dealing with this question.
R_Win
Calcite | Level 5
proc sql number outobs=5;
create table kk as
select * from sashelp.class desc group by designation order by sal descending;
quit;
Ksharp
Super User
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
ArtC
Rhodochrosite | Level 12
Just so that you will have one more choice take a look at the IDGROUP option on the OUTPUT statement in PROC MEANS/SUMMARY.
Ksharp
Super User
Thanks, Art Carpenter.
I will take a look.
:)

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 8055 views
  • 0 likes
  • 5 in conversation