Created
September 21, 2019 18:42
-
-
Save statgeek/93b7ee3318cf026e4b4507da7d6748f4 to your computer and use it in GitHub Desktop.
SAS - Add ranks - Select Top N records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*Create ranks for variables value; | |
proc rank data=sashelp.class out=class_ranked | |
/* (where= (rank_weight < 4)) */ | |
; | |
var weight; | |
ranks rank_weight; | |
run; | |
*display output; | |
title 'Unsorted but ranked'; | |
proc print data=class_ranked; | |
run; | |
*sort for display; | |
proc sort data=class_ranked; | |
by rank_weight; | |
run; | |
title 'Sorted and ranked'; | |
proc print data=class_ranked; | |
run; | |
*filter out the top 3 regardless of the number of ties; | |
data final; | |
set class_ranked; | |
by rank_weight; | |
if first.rank_weight then group + 1; | |
if group <= 3; | |
run;*Create ranks for variables value; | |
proc rank data=sashelp.class out=class_ranked | |
/* (where= (rank_weight < 4)) */ | |
; | |
var weight; | |
ranks rank_weight; | |
run; | |
*display output; | |
title 'Unsorted but ranked'; | |
proc print data=class_ranked; | |
run; | |
*sort for display; | |
proc sort data=class_ranked; | |
by rank_weight; | |
run; | |
title 'Sorted and ranked'; | |
proc print data=class_ranked; | |
run; | |
*filter out the top 3 regardless of the number of ties; | |
data final; | |
set class_ranked; | |
by rank_weight; | |
if first.rank_weight then group + 1; | |
if group <= 3; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment