Administrative functions > Data conversion programs > Converting Quantum data and programs with qtsas > Interface between Quantum and SAS > Variables and values
 
Variables and values
To understand how an axis becomes a variable, look at the different types of element you can have and see how they appear in the SAS files. The simplest axis is one in which the elements are single-coded. Take sex as an example. The axis:
l sex
col 110;Base;Male;Female;Not stated='&'
becomes:
proc format;
  value sexfmt
       1 = 'Male'
       2 = 'Female'
       3 = 'Not stated'
   ;
run;
data;
   infile "statdata";
   input
   sex
   ;
format sex sexfmt.;
run;
In the axis, the element’s condition determines the code which represents the response in the data. In the variable, the values for each answer are determined solely by the element’s position in the axis: ‘Not stated’ is the third answer so it becomes value 3 in the SAS variable. However, if an element in the axis contains no respondents (because no one gave that answer), that element is ignored and subsequent elements are renumbered. Thus, if column 110 of the Quantum data file never contains a code 2, the SAS specification for sex is:
proc format;
   value sexfmt
        1 = 'Male'
        2 = 'Not stated'
   ;
The base element in the axis definition is a count of respondents in the axis rather than an answer so it is ignored. Axes which contain only a base are ignored.
A similar thing happens with numeric data specified using the Quantum val statement. qtsas creates a format description for the variable listing the values present in the data. These will not be the numeric values in the Quantum data but codes allocated to those values according to the element’s position in the axis (and whether or not that element contains any respondents). qtsas then assigns this format to the variable, as shown below.
l persons
val c(8,9);Base;i;1 person;2-3 people;4-5 people;6-9 people;
+More than 9 people=10+
becomes:
proc format;
  value persofmt
         1 = '1 person'
         2 = '2-3 people'
         3 = '4-5 people'
         4 = '6-9 people'
         5 = 'More than 9 people'
   ;
run;
data;
   infile "statdata;
   input
   person
   ;
format person persofmt.;
The axis name has been truncated to five characters to make the format name. You might want to ensure that all the original Quantum axes have names of fewer than five characters to avoid duplicate names in the SAS data description (tmpxxy and tmpxxz would both become tmpxxfmt).
SAS does not handle multicoded data so qtsas converts it into the standard SAS format. When an axis is multicoded, qtsas creates as many variables as there are elements used in the axis. Each variable is named according to the axis name, but has a numeric suffix associated with the element’s position in the axis. For example, the multicoded axis:
l color
col 115;Base;Red;Blue;Green;Yellow;Others='&'
is converted into five variables named _color1 to _color5. The variable names start with an underscore (_) indicating that they are derived variables rather than variables related directly to a Quantum axis.
Each variable has two values: 1 if the respondent gave that answer, or 0 if they did not. Since there are no other values, no entry is generated in the proc format section. Instead, the answers which the variables represent are defined in the format section as follows:
label _color1 = "Red";
label _color2 = "Blue";
label _color3 = "Green";
label _color4 = "Yellow";
label _color5 = "Other";
As with single-coded variables, any unused values are ignored and subsequent items are renumbered.
Sometimes responses are coded with numeric codes of more than one digit; for example, 500 for a VW Scirocco, 520 for an Audi Quattro. Axes for data of this type will often be set up with fld or bit statements. If so, qtsas deals with them in same way as for multicoded axes. Thus, the axis:
l cars
fld (c126,c129) :3;Base;VW/Audi=500-572;Honda=990,991
is converted into two variables _cars1 and _cars2 labeled with the element text defined in the axis:
data;
   infile "statdata";
   cars
   ;
label _cars1 = "VW/Audi";
label _cars2 = "Honda";
If a respondent answers all questions in the questionnaire, the record will contain one value for each variable. If some questions are unanswered, or if filtering excludes a respondent from the axis, qtsas inserts a dot in the appropriate positions in the records. In SAS, the dot is called the missing value.
Quantum runs can be weighted. In Quantum, weights (apart from pre- and postweights) are defined in the tab section. qtsas converts the weighting matrix into a variable with a numeric suffix, and appends each respondent’s weight to the end of the record. Because the weight variable is not a bona fide Quantum axis, qtsas starts the variable name with an underscore. Thus, the statement:
wm1 sex;factor;100;200
appears at the end of the data list as _weight0, and records have either 100 or 200 as their last value, depending on whether the respondent is male or female.
For example:
proc format;
   value sexfmt
          1 = 'Male'
          2 = 'Female'
    ;
run;
data;
   infile "statdata";
   input
   sex
  _weight0
   ;
format sex sexfmt.;
label _weight0 = "@weight0';
run;
The format definition for a weighting variable is the same as the variable name except that the underscore is replaced with an @ sign. If the run contains more than one weighting matrix, the second matrix is named @weight1, the third is named @weight2, and so on.
To transfer data in numeric variables to the SAS data file, you need to create a namedinc statement for each numeric variable. namedinc statements should be defined after any global titles but before your tab statements and are in the form:
namedinc data_spec [;options]
The data_spec can be anything which gives an integer or float result.
The options available are:
Option
Explanation
anlev=
Specifies the analysis level; this is mandatory for levels data.
varname=
User-defined name of the variable; this is optional.
vartext=
One-line description of the variable; this is optional.
missing=
missing= as with inc=; this is optional.
For example:
namedinc shop;vartext=Number of shops visited
If, however, a numeric variable called shop does not exist, you can define it by specifying which columns it refers to. It could, for example, be written as:
namedinc c(213,214);varname=shop;vartext=Number of shops visited
If you do not specify a variable name (varname=), Quantum sets the name to the variable’s data_spec. If you do not assign a description to the variable (vartext=), Quantum makes the description the same as its name.
Numeric variables do not have a predefined set of values, so there is no proc format section. Instead, the variable is defined with a label statement:
label shop = "shop";
and the exact value of the variable is placed in the appropriate place in each record.
Note Before the namedinc statement was introduced into Quantum in version 5e.5b, numeric variables could be exported to SAS by specifying the variable with inc= on a dummy tab statement. For backward-compatibility, this method can still be used, but when writing new Quantum specs, you should now use namedinc instead.
See also
Interface between Quantum and SAS