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

Greeting!

SAS Community

 

What I have

SiteA_NA_MedianB_NB_MedianC_NC_Median
130246.53064.03043.0
25245.0599.0568.0
41118.0173.0157.0
62261.5240.52118.0
76342.0653.01035.0
89230.0975.0959.0
1215285.01575.01364.0
134246.54109.04127.0
144254.5463.0578.0
211681.0139.0132.0
221153.01153.0274.0
262152.5273.5270.0
287186.0745.0730.0
302406.02102.5446.5
376175.0641.5628.5
401138.0158.0143.0
511205.01111.0174.0
523284.0378.0366.0
724235.5470.5457.5
742333.5266.0257.5
802254.0262.0260.0
881415.01104.0173.0
964276.54114.0488.5

 

What I want

SiteA_NA_MedianA_RankB_NB_MedianB_RankC_NC_MedianC_Rank
3761751641.51628.51
287186274527302
89230397579598
724235.54470.56457.57
2524555991056811
130246.563064530435
134246.56410911412714
144254.58463457812
964276.59411412488.513
1215285111575713649
7634212653310354
511205-1111-174-
802254-262-260-
62261.5-240.5-2118-
523284-378-366-
742333.5-266-257.5-
41118-173-157-
211681-139-132-
221153-1153-274-
262152.5-273.5-270-
302406-2102.5-446.56
401138-158-143-
881415-1104-173-

 

to add a ranking variables A_Rank for any observation if A_N > 3, then assign a ranking score based on the A_Median value, the smallest A_Median will be assigned to 1 and asending up, the example above was sorted on A_Rank to show the idea.

Will do the same for B_N/B_Median and C_N/C_Meidan.

 

I know I can do it through splitting the dataset into A, B and C and use sort and use +1 notation, and merge the dataset again.

But that is not efficient and want to know what other solution would work without splitting the dataset.

 

Thank you so much!  

  

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards expandtabs;
input Site A_N A_Median B_N B_Median C_N C_Median;

_A_Median=A_Median;if A_N < 4 then call missing(_A_Median);
_B_Median=B_Median;if B_N < 4 then call missing(_B_Median);
_C_Median=C_Median;if C_N < 4 then call missing(_C_Median);

cards;
1 30 246.5 30 64.0 30 43.0
2 5 245.0 5 99.0 5 68.0
4 1 118.0 1 73.0 1 57.0
6 2 261.5 2 40.5 2 118.0
7 6 342.0 6 53.0 10 35.0
8 9 230.0 9 75.0 9 59.0
12 15 285.0 15 75.0 13 64.0
13 4 246.5 4 109.0 4 127.0
14 4 254.5 4 63.0 5 78.0
21 1 681.0 1 39.0 1 32.0
22 1 153.0 1 153.0 2 74.0
26 2 152.5 2 73.5 2 70.0
28 7 186.0 7 45.0 7 30.0
30 2 406.0 2 102.5 4 46.5
37 6 175.0 6 41.5 6 28.5
40 1 138.0 1 58.0 1 43.0
51 1 205.0 1 111.0 1 74.0
52 3 284.0 3 78.0 3 66.0
72 4 235.5 4 70.5 4 57.5
74 2 333.5 2 66.0 2 57.5
80 2 254.0 2 62.0 2 60.0
88 1 415.0 1 104.0 1 73.0
96 4 276.5 4 114.0 4 88.5
;

proc rank data=have out=want ties=dense;
var  _A_Median  _B_Median _C_Median ;
ranks   A_rank  B_rank C_rank  ;
run;

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

You've been around for a while now, surely you know that the best way to get help is to provide data in a usable format?

 

Ksharp
Super User
data have;
infile cards expandtabs;
input Site A_N A_Median B_N B_Median C_N C_Median;

_A_Median=A_Median;if A_N < 4 then call missing(_A_Median);
_B_Median=B_Median;if B_N < 4 then call missing(_B_Median);
_C_Median=C_Median;if C_N < 4 then call missing(_C_Median);

cards;
1 30 246.5 30 64.0 30 43.0
2 5 245.0 5 99.0 5 68.0
4 1 118.0 1 73.0 1 57.0
6 2 261.5 2 40.5 2 118.0
7 6 342.0 6 53.0 10 35.0
8 9 230.0 9 75.0 9 59.0
12 15 285.0 15 75.0 13 64.0
13 4 246.5 4 109.0 4 127.0
14 4 254.5 4 63.0 5 78.0
21 1 681.0 1 39.0 1 32.0
22 1 153.0 1 153.0 2 74.0
26 2 152.5 2 73.5 2 70.0
28 7 186.0 7 45.0 7 30.0
30 2 406.0 2 102.5 4 46.5
37 6 175.0 6 41.5 6 28.5
40 1 138.0 1 58.0 1 43.0
51 1 205.0 1 111.0 1 74.0
52 3 284.0 3 78.0 3 66.0
72 4 235.5 4 70.5 4 57.5
74 2 333.5 2 66.0 2 57.5
80 2 254.0 2 62.0 2 60.0
88 1 415.0 1 104.0 1 73.0
96 4 276.5 4 114.0 4 88.5
;

proc rank data=have out=want ties=dense;
var  _A_Median  _B_Median _C_Median ;
ranks   A_rank  B_rank C_rank  ;
run;
zimcom
Pyrite | Level 9
Thanks, I really appreciated your help!

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
  • 3 replies
  • 556 views
  • 4 likes
  • 3 in conversation