Computing the sum of multiple variables/positions

 

You can sum variables or record/column locations easily using the COMPUTE statement in the Glossary.

 

The syntax is:

 

COMPUTE new variable (or record/column location) = variable (or record/column location) A (number of variables (or record/column locations)

 

Example 1: Adding ten variables

 

COMPUTE TOTAL_AMOUNT = AMOUNT_1 A10

 

meaning, "add the next 10 values beginning in variable AMOUNT_1 and store the results in variable TOTAL_AMOUNT."

 

Example 2: Adding ten record/column locations

 

COMPUTE 1/100:2 = 1/5 A10

 

meaning, "add the next 10 values beginning in record/column location 1/5 and store the results in record/column location 1/100:2." 

Related topics:

COMPUTE

COMPUTE Examples