Arithmetic functions (COMPUTE command)

COMPUTE WtChange=ABS(Weight1-Weight2).
COMPUTE NewVar=RND((V1/V2)*100).
COMPUTE Income=TRUNC(Income).
COMPUTE MinSqrt=SQRT(MIN(V1,V2,V3,V4)).
 
COMPUTE Test = TRUNC(SQRT(X/Y)) * .5.
COMPUTE Parens = TRUNC(SQRT(X/Y) * .5).
  • WtChange is the absolute value of Weight1 minus Weight2.
  • NewVar is the percentage V1 is of V2, rounded to an integer.
  • Income is truncated to an integer.
  • MinSqrt is the square root of the minimum value of the four variables V1 to V4. MIN determines the minimum value of the four variables, and SQRT computes the square root.
  • The last two examples above illustrate the use of parentheses to control the order of execution. For a case with value 2 for X and Y, Test equals 0.5, since 2 divided by 2 (X/Y) is 1, the square root of 1 is 1, truncating 1 returns 1, and 1 times 0.5 is 0.5. However, Parens equals 0 for the same case, since SQRT(X/Y) is 1, 1 times 0.5 is 0.5, and truncating 0.5 returns 0.