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 |
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?
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.
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?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.