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

## Ranking

I have a dataset with 9 hospitals and specimen types ranging 0-4 where 4=unsatisfactory. I need to calculate specimen types for each hospital and give rankings to the hospital according to the unsatisfactory specimen(4) percentages. How can we do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Ranking

1. Calculate the percent of unsatisfactory per hospital. Depending on the data this could be proc freq or means.
2. Use PROC RANK to rank the data or order it descending and apply ranks manually.

Example below. Without the information request by @PaigeMiller we won't be able to help you further. Please include your code, log and example data if you run into issues.

``````proc freq data=hospitalData noprint;
table hospital*specimen / out=hosp_spec outpct;
run;

proc rank data=hosp_spec out=want;
where specimen = '4';
var pct_row;
ranks rank_pct_row;
run;``````

@SriCh1 wrote:

I have a dataset with 9 hospitals and specimen types ranging 0-4 where 4=unsatisfactory. I need to calculate specimen types for each hospital and give rankings to the hospital according to the unsatisfactory specimen(4) percentages. How can we do this?

9 REPLIES 9
Diamond | Level 26

## Re: Ranking

@SriCh1 wrote:

I have a dataset with 9 hospitals and specimen types ranging 0-4 where 4=unsatisfactory. I need to calculate specimen types for each hospital and give rankings to the hospital according to the unsatisfactory specimen(4) percentages. How can we do this?

I'm not sure what "calculate" means in this context. Does it mean you need to count the number of unsatisfactory specimens at each hospital? Can you show us a small portion of this data set following these instructions (and not via any other method).

--
Paige Miller
Calcite | Level 5

## Re: Ranking

Yes, count the number of unsatisfactory specimens for each hospital, convert it into a percentage, and then give ranking according to the percentage.

Diamond | Level 26

## Re: Ranking

Repeating: "Can you show us a small portion of this data set following these instructions (and not via any other method)."

--
Paige Miller
Super User

## Re: Ranking

1. Calculate the percent of unsatisfactory per hospital. Depending on the data this could be proc freq or means.
2. Use PROC RANK to rank the data or order it descending and apply ranks manually.

Example below. Without the information request by @PaigeMiller we won't be able to help you further. Please include your code, log and example data if you run into issues.

``````proc freq data=hospitalData noprint;
table hospital*specimen / out=hosp_spec outpct;
run;

proc rank data=hosp_spec out=want;
where specimen = '4';
var pct_row;
ranks rank_pct_row;
run;``````

@SriCh1 wrote:

I have a dataset with 9 hospitals and specimen types ranging 0-4 where 4=unsatisfactory. I need to calculate specimen types for each hospital and give rankings to the hospital according to the unsatisfactory specimen(4) percentages. How can we do this?

Calcite | Level 5

## Re: Ranking

This is the sample dataset
HOSPITAL SPEC_TYPE
Hospital A 0
Hospital B 2
Hospital B 3
Hospital C 1
Hospital A 4
Hospital A 4
Hospital E 2
Hospital D 4
Diamond | Level 26

## Re: Ranking

Please note that in the future, we're going to insist on you providing data according via working SAS data step code (you can follow these instructions), and you will get faster and probably more correct responses by doing so.

As you have provided the data, just change the names of the variables and the names of the input data set in the code from @Reeza to match your variable names. You will need to add the SPARSE option to the TABLES statement.

--
Paige Miller
Calcite | Level 5

## Re: Ranking

I did not know what was wrong with my error. Below I included the log part.

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 Proc FREQ data=Newborn.have noprint;
74 TABLES SPEC_TYPE*HOSPITAL/out=Newborn.percent;
75 run;

NOTE: There were 3723 observations read from the data set NEWBORN.HAVE.
NOTE: The data set NEWBORN.PERCENT has 33 observations and 4 variables.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.02 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
memory 2504.87k
OS Memory 34620.00k
Timestamp 05/03/2021 11:46:12 AM
Step Count 233 Switch Count 10
Page Faults 0
Page Reclaims 565
Page Swaps 0
Voluntary Context Switches 85
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 1328

76 proc rank data=Newborn.percent out=Newborn.final;
77 where SPEC_TYPE = 0;
78 var pct_row;
ERROR: Variable PCT_ROW not found.
79 ranks rank_pct_row;
80 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set NEWBORN.FINAL may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set NEWBORN.FINAL was not replaced because this step was stopped.
NOTE: PROCEDURE RANK used (Total process time):
real time 0.01 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 729.96k
OS Memory 33452.00k
Timestamp 05/03/2021 11:46:12 AM
Step Count 234 Switch Count 0
Page Faults 0
Page Reclaims 85
Page Swaps 0
Voluntary Context Switches 42
Involuntary Context Switches 0
Block Input Operations 288
Block Output Operations 16

81
82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
94
Diamond | Level 26

## Re: Ranking

`ERROR: Variable PCT_ROW not found.`

Sometimes these things can be solved simply by LOOKING AT the data sets. In this case, please look at the data set NEWBORN.PERCENT and see if the variable name is something other than PCT_ROW. If it is a different name, then use the name that is present in that data set.

--
Paige Miller
Super User

## Re: Ranking

You forgot the outpct in the TABLE statement.
Discussion stats
• 9 replies
• 796 views
• 1 like
• 3 in conversation