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

From another similar question on these boards I found the following solution:

 

%let trim=0.05;
data trimmed;
set have
Nobs=NN;
if &trim*NN < _N_ <= (1-&trim)*NN
then output;
run;

1)  Do you concur with this way of trimming the tails?  (I'm not exactly sure what's going on with this.  Just want it to work.)

 

2)  Data needs to be sorted by the relevant variable we want to trim, yes?

 

Thanks!

 

Nicholas Kormanik

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Opps. should use 


proc rank data=sashelp.cars groups=100 out=temp ;
 var invoice;
 ranks rank;
run;
data want;
 set temp;
 if 4 < rank < 94 ;
run;


Due to the fact that rank is 0-99 .


View solution in original post

6 REPLIES 6
Reeza
Super User

Depends. Rules of 5% is vague, and often confused with percentiles. 

So define your rules first. 

NKormanik
Barite | Level 11

The approach I'm presently using is the manual, long-about way.

 

First running Proc Univariate I am obtaining the _P5_ and _P95_ actual numbers (say, 30 and 156).

 

I then plug these numbers into the following code.

 

data tails_trimmed_5_percent;
set have;
where 30 <= N <= 156;
run;

I have many such databases.  And I was thinking there might be a more direct general approach.

 

Such as, just imagining, mind you....

 

where (lower_tail_5_percent) <= N <= (upper_tail_5_percent);

 

But, appears life ain't that easy.

 

 

Ksharp
Super User

A fast way to get it is using proc rank:

proc rank data=sashelp.cars groups=100 out=temp;
 var invoice;
 ranks rank;
run;
data want;
 set temp;
 if 5 < rank < 95 ;
run;

Another way is using IML, you want IML code ?

NKormanik
Barite | Level 11

Yes, please.  IML code, too.

 

Thanks a million!

 

Ksharp
Super User
Here is . I set the value greater than 95th or less than 5th be missing .


data have;
 do i=1 to 100;
  a=ceil(ranuni(1)*100);
  b=ceil(ranuni(2)*100);
  output;
 end;
 drop i;
run;


%let low=0.05 ;
%let high=0.95 ;

proc iml;
use have;
read all var _num_ into x[c=vname];
close have;
call qntl(q,x,{&low ,&high});

do i=1 to ncol(x);
 x[loc(x[,i]q[2,i]),i]=.;
end;

create want from x[c=vname];
append from x;
close want;

quit;
Ksharp
Super User
Opps. should use 


proc rank data=sashelp.cars groups=100 out=temp ;
 var invoice;
 ranks rank;
run;
data want;
 set temp;
 if 4 < rank < 94 ;
run;


Due to the fact that rank is 0-99 .


hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 5333 views
  • 3 likes
  • 3 in conversation