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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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