From: sole on
hi guys.
I need your help.

I have to calculate the addition of every two rows of my dataset, in
every possible combination... to find the combination that is equal to
a certain number...
i.e:

I have this and I want to know which combination makes 10:
A val
x 1
y 7
z 9
h 3


I need this:

y+h or x+z

maybe, I could transpose, but...
I only need a variable that tells me which combination is the one I
want..
thank you


From: Ya on
On May 10, 7:50 am, sole <pho...(a)katamail.com> wrote:
> hi guys.
> I need your help.
>
> I have to calculate the addition of every two rows of my dataset, in
> every possible combination... to find the combination that is equal to
> a certain number...
> i.e:
>
> I have this and I want to know which combination makes 10:
> A   val
> x    1
> y    7
> z    9
> h    3
>
> I need this:
>
> y+h  or   x+z
>
> maybe, I could transpose, but...
> I only need a variable that tells me which combination is the one I
> want..
> thank you

proc sql will make this quite easy:

data xx;
input A $ val;
cards;
x 1
y 7
z 9
h 3
;

proc sql;
select a.a as aa,b.a as ba, compress(a.a||'-'||b.a) as pair,
sum(a.val,b.val) as sum
from xx a, xx b
where a.a^=b.a
;

aa ba pair sum
-----------------------------------------------
x y x-y 8
x z x-z 10
x h x-h 4
y x y-x 8
y z y-z 16
y h y-h 10
z x z-x 10
z y z-y 16
z h z-h 12
h x h-x 4
h y h-y 10
h z h-z 12

Ya
From: Ya on
On May 10, 9:28 am, Ya <huang8...(a)gmail.com> wrote:
> On May 10, 7:50 am, sole <pho...(a)katamail.com> wrote:
>
>
>
>
>
> > hi guys.
> > I need your help.
>
> > I have to calculate the addition of every two rows of my dataset, in
> > every possible combination... to find the combination that is equal to
> > a certain number...
> > i.e:
>
> > I have this and I want to know which combination makes 10:
> > A   val
> > x    1
> > y    7
> > z    9
> > h    3
>
> > I need this:
>
> > y+h  or   x+z
>
> > maybe, I could transpose, but...
> > I only need a variable that tells me which combination is the one I
> > want..
> > thank you
>
> proc sql will make this quite easy:
>
> data xx;
> input A $ val;
> cards;
> x    1
> y    7
> z    9
> h    3
> ;
>
> proc sql;
> select a.a as aa,b.a as ba, compress(a.a||'-'||b.a) as pair,
> sum(a.val,b.val) as sum
> from xx a, xx b
> where a.a^=b.a
> ;
>
>  aa        ba        pair                    sum
>  -----------------------------------------------
>  x         y         x-y                       8
>  x         z         x-z                      10
>  x         h         x-h                       4
>  y         x         y-x                       8
>  y         z         y-z                      16
>  y         h         y-h                      10
>  z         x         z-x                      10
>  z         y         z-y                      16
>  z         h         z-h                      12
>  h         x         h-x                       4
>  h         y         h-y                      10
>  h         z         h-z                      12
>
> Ya- Hide quoted text -
>
> - Show quoted text -

I just noticed that there are duplicates 'x-y'='y-x' so, made some
change to get rid of it:

data xx;
input A $ val;
row=_n_;
cards;
x 1
y 7
z 9
h 3
;

proc sql;
select a.a as aa,b.a as ba, compress(a.a||'-'||b.a) as pair,
sum(a.val,b.val) as sum
from xx a, xx b
where a.a^=b.a and a.row < b.row
;

From: sole on
On 10 Mag, 18:28, Ya <huang8...(a)gmail.com> wrote:
> On May 10, 7:50 am, sole <pho...(a)katamail.com> wrote:
>
>
>
> > hi guys.
> > I need your help.
>
> > I have to calculate the addition of every two rows of my dataset, in
> > every possible combination... to find the combination that is equal to
> > a certain number...
> > i.e:
>
> > I have this and I want to know which combination makes 10:
> > A   val
> > x    1
> > y    7
> > z    9
> > h    3
>
> > I need this:
>
> > y+h  or   x+z
>
> > maybe, I could transpose, but...
> > I only need a variable that tells me which combination is the one I
> > want..
> > thank you
>
> proc sql will make this quite easy:
>
> data xx;
> input A $ val;
> cards;
> x    1
> y    7
> z    9
> h    3
> ;
>
> proc sql;
> select a.a as aa,b.a as ba, compress(a.a||'-'||b.a) as pair,
> sum(a.val,b.val) as sum
> from xx a, xx b
> where a.a^=b.a
> ;
>
>  aa        ba        pair                    sum
>  -----------------------------------------------
>  x         y         x-y                       8
>  x         z         x-z                      10
>  x         h         x-h                       4
>  y         x         y-x                       8
>  y         z         y-z                      16
>  y         h         y-h                      10
>  z         x         z-x                      10
>  z         y         z-y                      16
>  z         h         z-h                      12
>  h         x         h-x                       4
>  h         y         h-y                      10
>  h         z         h-z                      12
>
> Ya

sorry.... but what do yoo mean wirh a and b... it doesn' works...
the log tells me "found in more than a column"
From: PJ on
data xx;
input A $ val;
cards;
x 1
y 7
z 9
h 3
;


proc sql;
create table xx1 as
select a.a as aa, b.a as ba, catx('+', a.a, b.a) as pair,
sum(a.val,b.val) as sum
from xx a, xx b
where calculated sum = 10 and a.a < b.a;


;