Adding numbers in columns - HELP please.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding numbers in columns - HELP please.

Fahim Jafary
I have a dataset which records ECG changes in variables v1 to v6 as
positive and negative numbers as well as zeros (if there is no change).

I want to be able to

1.  Add the positive numbers from v1 to v6 to get a cumulative "score",
ignoring the negative values (so, for values 1, 2, 1, -2, 1, -3   I should
get a "score" of 5)
2.  Add the positive AND negative numbers from v1 to v6 to get a second
cumulative "score" but IGNORING the negative or positive sign (so for
values 1, 2, 1, -2, 1, -3  I should get a "score" of 10)
3.  Add the negative numbers from v1 to v6 to get a third "score" but
IGNORING the positive values (so for values 1, 2, 1, -2, 1, -3  I should
get a score of 5).

Can someone help me with the syntax on this one.  I'll be very grateful

Fahim H. Jafary
Aga Khan University Hospital
Karachi, Pakistan
Reply | Threaded
Open this post in threaded view
|

Re: Adding numbers in columns - HELP please.

Jason Burke
Hi Fahim,

This should achieve what you require:

VECTOR var = v1 TO v6 .
LOOP #n = 1 To 6.
IF (var(#n) GE 0) pos_score = SUM(pos_score, var(#n)) .
COMPUTE abs_score = SUM(abs_score, ABS(var(#n))) .
IF (var(#n) LE 0) neg_score = SUM(neg_score, var(#n)) .
END LOOP .
EXECUTE .

Cheers,


Jason

On 8/26/06, Fahim Jafary <[hidden email]> wrote:

> I have a dataset which records ECG changes in variables v1 to v6 as
> positive and negative numbers as well as zeros (if there is no change).
>
> I want to be able to
>
> 1.  Add the positive numbers from v1 to v6 to get a cumulative "score",
> ignoring the negative values (so, for values 1, 2, 1, -2, 1, -3   I should
> get a "score" of 5)
> 2.  Add the positive AND negative numbers from v1 to v6 to get a second
> cumulative "score" but IGNORING the negative or positive sign (so for
> values 1, 2, 1, -2, 1, -3  I should get a "score" of 10)
> 3.  Add the negative numbers from v1 to v6 to get a third "score" but
> IGNORING the positive values (so for values 1, 2, 1, -2, 1, -3  I should
> get a score of 5).
>
> Can someone help me with the syntax on this one.  I'll be very grateful
>
> Fahim H. Jafary
> Aga Khan University Hospital
> Karachi, Pakistan
>