Next: IF, Previous: COUNT, Up: Data transformations [Contents][Index]
FLIP /VARIABLES=var_list /NEWNAMES=var_name.
FLIP
transposes rows and columns in the active dataset. It
causes cases to be swapped with variables, and vice versa.
All variables in the transposed active dataset are numeric. String variables take on the system-missing value in the transposed file.
N
subcommands are required. If specified, the VARIABLES
subcommand
selects variables to be transformed into cases, and variables not
specified are discarded. If the VARIABLES
subcommand is omitted, all
variables are selected for transposition.
The variables specified by NEWNAMES
, which must be a
string variable, is
used to give names to the variables created by FLIP
. Only the
first 8 characters of the variable are used. If
NEWNAMES
is not
specified then the default is a variable named CASE_LBL, if it exists.
If it does not then the variables created by FLIP
are named VAR000
through VAR999, then VAR1000, VAR1001, and so on.
When a NEWNAMES
variable is available, the names must be canonicalized
before becoming variable names. Invalid characters are replaced by
letter ‘V’ in the first position, or by ‘_’ in subsequent
positions. If the name thus generated is not unique, then numeric
extensions are added, starting with 1, until a unique name is found or
there are no remaining possibilities. If the latter occurs then the
FLIP
operation aborts.
The resultant dictionary contains a CASE_LBL variable, a string
variable of width 8, which stores the names of the variables in the
dictionary before the transposition. Variables names longer than 8
characters are truncated. If FLIP
is called again on
this dataset, the CASE_LBL variable can be passed to the NEWNAMES
subcommand to recreate the original variable names.
FLIP
honors N OF CASES
(see N OF CASES). It ignores
TEMPORARY
(see TEMPORARY), so that “temporary”
transformations become permanent.
In Example 12.5, data has been entered using DATA LIST
(see DATA LIST)
such that the first variable in the dataset is a string variable containing
a description of the other data for the case.
Clearly this is not a convenient arrangement for performing statistical analyses,
so it would have been better to think a little more carefully about how the data
should have been arranged.
However often the data is provided by some third party source, and you have
no control over the form.
Fortunately, we can use FLIP
to exchange the variables
and cases in the active dataset.
data list notable list /heading (a16) v1 v2 v3 v4 v5 v6 begin data. date-of-birth 1970 1989 2001 1966 1976 1982 sex 1 0 0 1 0 1 score 10 10 9 3 8 9 end data. echo 'Before FLIP:'. display variables. list. flip /variables = all /newnames = heading. echo 'After FLIP:'. display variables. list. |
As you can see in Results 12.3 before the FLIP
command has run there
are seven variables (six containing data and one for the heading) and three cases.
Afterwards there are four variables (one per case, plus the CASE_LBL variable)
and six cases.
You can delete the CASE_LBL variable (see DELETE VARIABLES) if you don’t need it.
Before FLIP:
After FLIP:
|
Next: IF, Previous: COUNT, Up: Data transformations [Contents][Index]