dummy |
Construct dummy variables for a factor |
dummy |
SAS Macro Programs: dummy
$Version: 1.3 (18 Mar 2001)
Michael Friendly
York University
Given a character or discrete numerical variable, this macro creates
dummy (0/1) variables to represent the levels of the original variable
in a regression model. If the original variable has c levels, (c-1)
new variables are produced (or c variables, if FULLRANK=0)
The dummy variables can be named by appending numbers to a prefix,
or by appending the value of the discrete variable to the prefix.
Parameters
- DATA=_LAST_
- The name of the input dataset. If not specified, the most
recently created dataset is used.
- OUT=
- The name of the output dataset. If not specified, the new
variables are appended to the input dataset.
- VAR=
- The name(s) of the input variable(s) to be dummy coded. Must be
specified. The variable can be character or numeric.
If several variables are given, specify their names individually
(lists such as X1-X5 are not allowed).
- PREFIX=
- Prefix used to create the names of dummy variabbles. The
default is 'D_'. The prefix may be empty.
- NAME=
- If NAME=VAL, the dummy variables are named by appending the
value of the VAR= variable to the prefix. Otherwise, the
dummy variables are named by appending numbers, 1, 2, ...
to the prefix. The resulting name must be 8 characters or
less.
- BASE=
- Indicates the level of the baseline category, which is given
values of 0 on all the dummy variables. BASE=_FIRST_
specifies that the lowest value of the VAR= variable is the
baseline group; BASE=_LAST_ specifies the highest value of
the vartiable. Otherwise, you can specify BASE=value to
make a different value the baseline group.
Example
With the input data set,
data test;
input y group $ @@;
cards;
10 A 12 A 13 A 18 B 19 B 16 C 21 C 19 C
;
The macro statement:
%dummy ( data = test, var = group) ;
produces two new variables, D_A and D_B. Group C is the baseline
category (corresponding to BASE=_LAST_)
OBS Y GROUP D_A D_B
1 10 A 1 0
2 12 A 1 0
3 13 A 1 0
4 18 B 0 1
5 19 B 0 1
6 16 C 0 0
7 21 C 0 0
8 19 C 0 0
See also