Sample 25090: Getting weighted ranks when there is no WEIGHT statement in PROC RANK
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
%macro rank ( dsn = /* data set name */
, wgt = /* weight variable */
, var = /* analysis variable */
, rank = /* name for the rank variable */
, quantile = /* 5 for quintiles */
/* 10 for deciles */
/* 20 for duo or demi deciles */
/* 100 for percentiles */
) ;
data _NULL_ ;
set &DSN end=last ;
sumofwgt + &wgt ;
if last then call symput ('SUM', trim(left(put(sumofwgt, best.))))
;
run ;
proc sort data = &DSN ;
by descending &VAR ;
run ;
data &DSN ;
set &DSN ;
drop sumofwgt ;
sumofwgt + &WGT ;
&rank = 0 ;
do i = 1 to ( &quantile - 1 ) ;
if ( ( &rank = 0 ) and ( sumofwgt le (( &SUM*i)/&quantile ) ) )
then &rank = i ;
end ;
if (&rank = 0) then &rank = &quantile ;
drop i ;
label &rank = "Rank for the Variable: &VAR." ;
run ;
%mend rank ;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This example uses a macro that will produce weighted ranks where QUANTILE= relates to the GROUPS= options in PROC RANK.
| Type: | Sample |
| Topic: | Analytics ==> Nonparametric Analysis SAS Reference ==> Procedures ==> RANK Analytics ==> Transformations
|
| Date Modified: | 2005-08-27 03:03:14 |
| Date Created: | 2005-01-26 16:18:02 |
Operating System and Release Information
| SAS System | Base SAS | All | 8 TS M0 | n/a |