Hi there
If I have a table, how can I get the top 50% of records into one table and thereafter the bottom 50% of records in another table?
I generally use PROC SQL;
Please assist.
Thank you
data _NULL_;
if 0 then set sashelp.snacks nobs=count;
call symputx('numobsDIV2' ,put(int(count/2),8. ));
call symputx('numobsDIV2_plus1',put(int(count/2)+1,8.));
STOP;
run;
%PUT &=numobsDIV2;
%PUT &=numobsDIV2_plus1;
PROC SQL noprint;
create table work.First_50_pct as
select *
from sashelp.snacks(firstobs=1 obs=&numobsDIV2.);
create table work.Last_50_pct as
select *
from sashelp.snacks(firstobs=&numobsDIV2_plus1. obs=MAX);
QUIT;
/* end of program */
If you have SAS9.4 .
proc sql;
create table top_50 as
select * from sashelp.class
having weight>=median(weight);
create table bottom_50 as
select * from sashelp.class
having weight<median(weight);
quit;
How is "top 50%" defined?
What about ties. Consider values such as
ID value
1 1
2 2
3 2
4 2
5 2
6 3
Where is "50%"?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.