how to to calculate the values within the range?

Reply
New Contributor
Posts: 4

how to to calculate the values within the range?

Hi Everyone,

How can I write a code to add all the observations of var1 which are within low and high range?

 

Table A           Table B

Var 1 var2    var1 Low High

10 50             7 10 19

11 52             8 20 29

12 54             9 30 39

13 56            10 40 49

14 58            11 50 59

15 60           12 60 69

16 62           13 70 79

17 64            17 80 89

22 66          22 90 99

27 68         27 100 109

32 70          32 110 119

37 72         37 120 129

42 74          42 130 139

 

Var 1, Low, high ==character variable

var2==numeric variable

 

Super User
Posts: 11,134

Re: how to to calculate the values within the range?

You should provide an example of your desired output for the example input. You question isn't quite clear.

 

And you want to SUM character values? Or do you mean to combine the data sets with some rule? If so you need to be a bit more explicti about what that rule may be.

Respected Advisor
Posts: 4,817

Re: how to to calculate the values within the range?

Maybe all you want is this:

 

proc sql;
create table C as
select B.*, sum(a.Var2) as lowHighSum
from B left join A 
    on input(A.Var1, best.) between input(Low, best.) and input(High, best.)
group by B.Var1, Low, High;
select * from C;
quit;
PG
Ask a Question
Discussion stats
  • 2 replies
  • 178 views
  • 0 likes
  • 3 in conversation