BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
batool89
Fluorite | Level 6

Hello,

 

I have a sample including the variables of Return, Earnings and Size from 1980 to 2015. I want to remove (delete) the higher and lower 1% of each variable's observations each year using SAS 9.4. however, I am not sure about the codes I should use.

 

can you please help me?

 

thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

The following delete the top and bottom 20% data for each year.

If you need 1% change GROUPS=100 and NOT IN (0 99) .

 

data air;
 set sashelp.air;
 year=year(date);
 drop date;
run;
proc rank data=air out=temp groups=5;
by year;
var air;
ranks r_air;
run;
data want;
 set temp;
 if r_air not in (0 4);
run;

View solution in original post

5 REPLIES 5
batool89
Fluorite | Level 6
thank you so much. can you please advise me how to extend the code to do this for each year?
Ksharp
Super User

The following delete the top and bottom 20% data for each year.

If you need 1% change GROUPS=100 and NOT IN (0 99) .

 

data air;
 set sashelp.air;
 year=year(date);
 drop date;
run;
proc rank data=air out=temp groups=5;
by year;
var air;
ranks r_air;
run;
data want;
 set temp;
 if r_air not in (0 4);
run;
MINX
Obsidian | Level 7

@Ksharp This is a good approach. But Proc Rank only works when obersvation numbers are larger than GROUPS size. I did a draft based on the reference by @Miracle

 

data air;
 set sashelp.retail;
 rename sales=air;
 drop date;
run;

proc means data=air noprint;
by year;
var air;
output out=stat
		p1=p1
		p99=p99;
run;

data r_air;
merge air(in=x) stat(keep=year p1 p99);
by year;
if x;
run;

data want;
 set r_air;
 if p1<=air<=p99;
run;
batool89
Fluorite | Level 6

thank you all. I appreciate your help. 

 

I tried Proc Rank and it worked.

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
  • 5 replies
  • 3480 views
  • 6 likes
  • 4 in conversation