BookmarkSubscribeRSS Feed
Citrine10
Obsidian | Level 7

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

3 REPLIES 3
sbxkoenk
SAS Super FREQ
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 */
Ksharp
Super User

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;
ballardw
Super User

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 2024

Innovate_SAS_Blue.png

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. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 316 views
  • 5 likes
  • 4 in conversation