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

I have dataset like this 

data have;
input subjid  value;
format subjid z3.;
cards;
001     -4
005     -4
003     30
002     -4
004     -4
006     26
007     6
;
run;

 

step1: Sorting by ascending and give rank number.

step2:subject with the same vaule are given the average of the rankings;

 

 

For step 2 : I have no idea how to output average of the rankings;

Please kindly help;

 

Final output result i want  like this ,

I hope that helps you understand my question

 

data want;
input subjid  value rank;
format subjid z3.;
cards;
001     -4    5.5
005     -4    5.5
003     30    1
002     -4    5.5
004     -4    5.5
006     26    2
007     6     3
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Proc Rank to the rescue:

data have;
input subjid  value;
format subjid z3.;
cards;
001     -4
005     -4
003     30
002     -4
004     -4
006     26
007     6
;
run;

proc rank data = have out = want DESCENDING;
  var value;
  ranks rank;
run;

B

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

1 REPLY 1
yabwon
Onyx | Level 15

Proc Rank to the rescue:

data have;
input subjid  value;
format subjid z3.;
cards;
001     -4
005     -4
003     30
002     -4
004     -4
006     26
007     6
;
run;

proc rank data = have out = want DESCENDING;
  var value;
  ranks rank;
run;

B

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 1 reply
  • 341 views
  • 0 likes
  • 2 in conversation