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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.