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%"?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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