## percentage of range

Solved
Frequent Contributor
Posts: 77

# percentage of range

Hi,

In the code below min_stat, max_stat, and range are computed correctly, however, pc_stat doesn't work.

``````data have;
do until (last.SO);
set have;
by unit SO;
min_stat = min(min_stat, distance);
max_stat = max(max_stat, distance);
end;

range = max_stat - min_stat;

pc_stat = (distance-min_stat)/range;
do until (last.SO);
set have;
by unit SO;
output;
end;
run;``````

The data below shows the input, incorrect pc_stat_get and the desired pc_stat_want. The typical excel equation is:J2 =(D2-F2)/H2 where distance = D2, min_stat = F2, range = H2, and pc_stat_want = J2. Thanks.

 unit SO distance date min_stat max_stat range pc_stat_get pc_stat_want 2801 1114 61879.683 23-Jan-18 61879.68 69663.15 7783.464 1 0 2801 1114 65404.52 24-Jan-18 61879.68 69663.15 7783.464 1 0.45286225 2801 1114 66928.735 25-Jan-18 61879.68 69663.15 7783.464 1 0.64868958 2801 1114 69270.521 26-Jan-18 61879.68 69663.15 7783.464 1 0.94955639 2801 1115 61887.203 23-Jan-18 61887.2 69652.83 7765.627 1 0 2801 1115 65411.952 24-Jan-18 61887.2 69652.83 7765.627 1 0.4538911 2801 1115 66937.299 25-Jan-18 61887.2 69652.83 7765.627 1 0.65031401 2801 1115 69260.203 26-Jan-18 61887.2 69652.83 7765.627 1 0.9494404

Accepted Solutions
Solution
‎01-30-2018 04:05 PM
Super User
Posts: 6,642

## Re: percentage of range

[ Edited ]

The RANGE calculation is fine.

The PC_STAT calculation should go just before the OUTPUT statement.

I'm not sure the WANT example is entirely correct for PC_STAT.  Shouldn't each group have an observation where PC_STAT is 1?

All Replies
Super User
Posts: 23,343

## Re: percentage of range

I think your formula is correct, not sure it's in the correct location. Try moving the RANGE to your DoW portion and the PC_STAT to after the second SET statement.

Solution
‎01-30-2018 04:05 PM
Super User
Posts: 6,642

## Re: percentage of range

[ Edited ]

The RANGE calculation is fine.

The PC_STAT calculation should go just before the OUTPUT statement.

I'm not sure the WANT example is entirely correct for PC_STAT.  Shouldn't each group have an observation where PC_STAT is 1?

☑ This topic is solved.