Numeric Calculations

Create a Numeric Calculation Automatic Variable

  1. Select Edit|Insert.
  2. Select Automatic Variable and click OK.
  3. Enter a variable name in the Variable Name box.
  4. Enter a variable label in the Variable Label box.
  5. Select Numeric Calculation from the Type of data to be stored drop-down box.
  6. Enter a numeric value in the Missing Code box. QDS will use this value if the numeric calculation cannot be evaluated to a single value. (The default value is -1.)
  7. Enter a calculation in the Numeric Calculation/String Expression box.
  8. Click OK.

Tip: See QDS Functions and Expressions for a full listing of QDS functions and expressions for use in QDS Automatic Variables.

Numeric calculations can be used to calculate values based on responses to previous questions.

For example, to calculate an average score based upon the values of five variables, you could have an Automatic Variable with the following options:

  • Variable Name: AVG_SCOR
  • Type of data to be stored: Numeric Calculation
  • Variable Label: Average Score
  • Numeric Calculation/String Expression: (SCORE1 + SCORE2 + SCORE3 + SCORE4 + SCORE5)/5

Automatic Variable Numeric Calculation

Another common use of numeric calculations is to calculate a result based on conditional expressions: The following 'If' statement:

  • If (Q1= 1 AND Q2 = 1, 1, if(Q1= 0 AND Q2 = 0, 2, if(Q1= 1 AND Q2 = 0, 3, if(Q1= 0 AND Q2 = 1, 4, 9))))

will return a different value depending on how Q1 and Q2 were answered. If both Q1 and Q2 were = 0, then it will return a “2”; other combinations will return 1, 3, 4, or 9.

Date of Birth Calculation

One common numeric expression is to calculate an Automatic Variable AGE based on date of birth (a previously collected Data Element named "DOB") and Today’s date (a previous Automatic Variable of type Today’s Date named "TODAY") with the following options:

  • Variable Name: AGE
  • Type of data to be stored: Numeric Calculation
  • Variable Label: Age calculated from DOB
  • Numeric Calculation/String Expression: AGE(DOB,TODAY)

Automatic Variable Date of Birth Calculation