Data editing > Basic elements > Variables and arrays > Data variables
 
Data variables
Quick reference
To refer to a single data variable in the C array, type:
cnumber
To refer to a field of data variables in the C array, type:
c(start_pos,end_pos)
To define a data variable, type:
data var_name sizes
before the edit section. To refer to it, use the same notation as above but replace the c with the variable’s name.
More information
At the start of every job, Quantum provides an array of 1,000 data cells called C. This array is sometimes referred to as the C matrix. The individual cells are called C-variables. Each C‑variable stores one ‘column’ of data. Quantum reads data from your data file into this array; for more information about how it does this, see How Quantum reads data.
For example, you might have a questionnaire which uses 43 columns to store the data. Quantum reads the data for each respondent into cells 1 to 43 of the C array, one respondent at a time. The codes from column 1 of the data are copied into cell 1 of the C array, the codes from column 2 of the data are copied into cell 2, and so on. When Quantum has finished with that respondent’s data it clears out the cells in the C array and reads the data for the next respondent, placing it in cells 1 to 43 of the array.
To access this data, define the columns whose contents you want to inspect or change. Take the questions about color that were mentioned earlier.The printed questionnaire indicates that the respondent’s favorite color will be coded into column 15. To look at this column, write:
c15
or
c(15)
The C may be in uppercase or lowercase, and the parentheses around the column number are optional.
To refer to column 43, write:
c43
or
c(43)
Now suppose you want to look at a field of columns such as the questionnaire serial number in columns 1 to 5. To tell Quantum that the serial number is in a field starting in column 1 and ending in column 5, write:
c(1,5)
The parentheses around the column numbers are obligatory.
C variables are reset to blank before a new respondent’s data is read. You can be certain that Quantum never muddles the contents of column 10 for the first respondent with those of c10 for the second respondent.
You can create your own data variables to store specific pieces of data. For example, in a shopping survey you might want to store data about visits to Sainsburys in an array called ‘sains’ and data about visits to Safeways in an array called ‘safe’.
Before you can use these arrays, you must create them. If each array is to contain 100 cells or columns of data, write:
data sains 100s
data safe 100s
before the edit section. The s at the end of each statement causes Quantum to recognize that, for example, safe1 is the same as safe(1), just as it knows that c15 and c(15) refer to the same column of data. If you created the arrays without the s, then Quantum would not recognize safe1 as being the same as safe(1).
Data variables which you create remain blank until you copy data into them. If the data about visits to Sainsburys is stored in columns 30 to 45, then you might copy this into cells 30 to 45 of the array called sains. To use this data, you can write statements which refer to sains30 to sains45. Unless you subsequently change the data in sains(30,45), each time you refer to one of those cells it is exactly the same as referring to c30, c45, and so on, in the C array, and to columns 30, 45, and so on, in the data file.
In this example, there is not much to be gained (apart from an immediate improvement in readability) by using your own data variables. However, when you have many columns of data per respondent, or a complicated Quantum program, named data variables can be very useful for improving readability and also for providing simple yet powerful facilities for data manipulation.
Further examples
c80
means column 80 of the C array
c(130,145)
means columns 130 to 145 inclusive of the C array
total(17)
means cell 17 of the array called total (parentheses are optional)
visits(134,136)
means cells 134, 135 and 136 of the array called visits
c(1,80)
means columns 1 to 80 inclusive of the C array
More information
For more information about creating and using named data variables, see Creating new variables.
See also
Variables and arrays