DECLARE Examples

 

Example 1: Declare a new variable

 

DECLARE NEW_VAR1

 

means, ‘Create a new variable called NEW_VAR1.’  NEW_VAR1 in this case is assumed to be a width of 12 because no width was specified.

 

Example 2: Declare 4 new variables

 

DEC NEW_VAR1,NEW_VAR2,NEW_VAR3,NEW_VAR4

 

means, ‘Create 4 new variables called NEW_VAR1, NEW_VAR2, NEW_VAR3 and NEW_VAR4.’ All 4 variables are assumed to be a width of 12 because no width was specified.

 

Example 3: Declare 2 new variables and ASSIGN values based on the contents of another existing variable

 

DECLARE Q1_YES,Q1_NO

IF GENDER (1) ASSIGN Q1_YES = (1)

IF GENDER (2) ASSIGN Q1_NO = (1)

 

means, ‘Create 2 new variables called Q1_YES and Q1_NO'. If the value for the variable GENDER is "1", assign the value of "1" to Q1_YES. If the value for the existing variable GENDER is "2", assign the value of "1" to Q1_NO.’ Both new variables are assumed to be a width of 12 because no width was specified. 

 

Example 4: Declare a new variable and assign an existing variable into the new variable

 

DEC NEW_VAR1 = Q2A

 

means, ‘Create a new variable called NEW_VAR1 and assign the value of Q2A to NEW_VAR1.’  NEW_VAR1 in this case is assumed to be a width of 12 because no width was specified.

 

Example 5: Declare a new variable and assign an existing record/column location into the new variable

 

DECLARE NEW_VAR1 = 1/7:1

 

means, ‘Create a new variable called NEW_VAR1 and assign the value from record/column location 1/7 for a length of 12 because no width was specified.

 

Example 6: Declare 1 new variable and assign the constant value of 10000 into the new variable

 

DEC MAX_RECS = 10000

 

means, ‘Create 1 new variable called MAX_RECS'. Assign the constant value of 10000 to MAX_RECS. The width of MAX_RECS is assumed to be 5 to hold the value 10000.

 

Example 7: Declare 1 new variable and assign the constant value of 10000 into the new variable

 

DECLARE NEW_WEIGHT:9 = 1.1234567

 

means, ‘Create 1 new variable called NEW_WEIGHT'. Assign the constant value of 1.1234567 to NEW_WEIGHT. The width of NEW_WEIGHT is assumed to be 9 with 7 decimal places to hold the value 1.1234567.

 

Example 8: Declare 1 new variable and compute the value of the new variable as two existing variables added together

 

DECLARE Q2_TOT = Q2A + Q2B

 

means, ‘Create 1 new variable called Q2_TOT'. Assign the value of Q2A plus Q2B into Q2_TOT. The width of Q2_TOT is assumed to be 1 because no width was specified.

 

Example 9: Declare a new variable with a width of 10

 

DEC NEW_VAR1:10

 

means, ‘Create a new variable called NEW_VAR1 with a width of 10.’

 

Example 10: Declare 1 new variable with a width of 4 and COMPUTE the value of the new variable as two existing variables added together and divided by 2

 

DECLARE Q2_AVG:4

IF GENDER (1) COMPUTE Q2_AVG = {Q2A + Q2B} / 2

 

means, ‘Create 1 new variable called Q2_AVG with a width of 4'. If the value for the variable GENDER is "1", assign the value of Q2A plus Q2B divided by a constant value of 2. The width of Q2_AVG is specified as 4.

 

Example 11: Declare 4 new variables with varying widths

 

DECLARE NEW_VAR1:2,NEW_VAR2:4,NEW_VAR3:5,NEW_VAR4:2

 

means, ‘Create 4 new variables called NEW_VAR1 with a width of 2, NEW_VAR2 with a width of 4, NEW_VAR3 with a width of 5 and NEW_VAR4 with a width of 2.’

 

Example 12: Declare a new variable and compute the value to be the total of 4 existing variables added together

 

DEC TOT_Q6A:2 = Q6A_1 A4

 

means, ‘Create a new variable called TOT_Q6A with a width of 2 and compute the total of variables Q6A_1, Q6A_2, Q6A_3, Q6A_4 added together into TOT_Q6A.’ The new variable TOT_Q6A must be wide enough to handle the total computed value.

 

Example 13: Declare 1 new variable and assign the constant value of 10000 into the new variable

 

DECLARE MAX_RECS:6 = 10000

 

means, ‘Create 1 new variable called MAX_RECS with a width of 6'. Assign the constant value of 10000 to MAX_RECS. The width of MAX_RECS is specified as 6.

 

Example 14: Declare 1 new variable and assign the constant value of "F" into the new variable

 

DECLARE FEMALE:1 = (F)

 

means, ‘Create 1 new variable called FEMALE with a width of 1'. Assign the constant value of "F" to FEMALE. The width of FEMALE is specified as 1.

 

Note: If the value being assigned into the new variable is alpha-numeric (for example, "FEMALE" or "F"), the value must be enclosed in parentheses. If the value is numeric, parentheses are optional.

 

Example 15: Declare a new variable and compute the value to be an existing variable multiplied by the constant value of 10

 

DECLARE INCOME:10 = INCOME_1 * 10

 

means, ‘Create a new variable called  INCOME with a width of 10 and multiply the value in INCOME_1 by a constant value of 10.’ The new variable INCOME must be wide enough to handle the total computed value.

Related topics:

DECLARE

ASSIGN

ASSIGN Examples

COMPUTE

COMPUTE Examples