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%"?
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.