percentage of range

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 77
Accepted Solution

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.

 

unitSOdistancedatemin_statmax_statrangepc_stat_getpc_stat_want
2801111461879.68323-Jan-1861879.6869663.157783.46410
2801111465404.5224-Jan-1861879.6869663.157783.46410.45286225
2801111466928.73525-Jan-1861879.6869663.157783.46410.64868958
2801111469270.52126-Jan-1861879.6869663.157783.46410.94955639
2801111561887.20323-Jan-1861887.269652.837765.62710
2801111565411.95224-Jan-1861887.269652.837765.62710.4538911
2801111566937.29925-Jan-1861887.269652.837765.62710.65031401
2801111569260.20326-Jan-1861887.269652.837765.62710.9494404

Accepted Solutions
Solution
4 weeks ago
Super User
Posts: 6,011

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?

View solution in original post


All Replies
Super User
Posts: 21,572

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
4 weeks ago
Super User
Posts: 6,011

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 83 views
  • 1 like
  • 3 in conversation