Hello,
I am so new to SAS progam and need help with my codes below. I am trying to find the top 10% of employees with highest salary.
DATA TOP10PS; SET SAS.T;
PROC SORT; BY DESCENDING SALARY;
DATA EE1; SET TOP10PS END=EOF;
IF EOF THEN DO;
FORMAT TENP 7.;
COUNT=_N_;
TENP = COUNT / 10;
IF COUNT <= TENP THEN OUTPUT;
END;
KEEP EE RACE SEX SALARY;
RUN;
DATA FINAL; SET EE1;
PROC PRINT N; ID EE; VAR RACE SEX SALARY;
RUN;
Your code wouldn't be recognized, by SAS, as being valid code. Conversely, the following would do what you want.
When you run a querry using SAS proc sql, &sqlobs. contains the number of records in the file:
/*as an example I'm substituting sashelp.class for sas.t*/ proc sql noprint; create table final as select * from sashelp.class (rename=(name=EE age=RACE weight=SALARY)) order by salary descending ; quit; data final (keep=EE RACE SEX SALARY); set final; if _n_/&sqlobs. gt .1 then stop; output; run; proc print; run;
HTH,
Art, CEO, AnalystFinder.com
Your code wouldn't be recognized, by SAS, as being valid code. Conversely, the following would do what you want.
When you run a querry using SAS proc sql, &sqlobs. contains the number of records in the file:
/*as an example I'm substituting sashelp.class for sas.t*/ proc sql noprint; create table final as select * from sashelp.class (rename=(name=EE age=RACE weight=SALARY)) order by salary descending ; quit; data final (keep=EE RACE SEX SALARY); set final; if _n_/&sqlobs. gt .1 then stop; output; run; proc print; run;
HTH,
Art, CEO, AnalystFinder.com
You could use proc rank to get the top decile first. Then you can sort that much smaller data set without further filtering.
proc rank data=sas.t
out=final (where=(salary_decile=9))
groups=10;
var salary;
ranks salary_decile;
run;
proc sort;
by descending salary;
run;
proc print n;
id ee;
var race sex salary;
run;
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.