![]() |
PING
0.9
Statistical data handling and processing in production environment
|
(Re)order the variables (columns) of a given dataset.
idsn : a dataset reference;varnum : (option) list of variables positions (numeric indexes) to consider so as to reorder the columns/fields of idsn; note that varnum=alpha is also accepted, so that, in that case, the variables in idsn are reordered alphabetically; incompatible with options varlst and varlike below; default: varnum=alpha, and the variables in the dataset idsn are reordered alphabetically when none of the parameteres varnum, varlst and varlike (see below) is passed;varlst : (option) list of variables names to consider so as to reorder the columns/fields of idsn; incompatible with options varnum above and varlike below; default: varlst=, i.e. it is not set;varlike : (option) table whose variables order will be applied to the dataset reference; incompatible with options varlst above and varlike above; default: varlike=, i.e. it is not set;ilib : (option) name of the input library; by default: empty, i.e. WORK is used,liblike : (option) name of the library where varlike is stored; by default: empty, i.e. ilib will be used in case varlike is set.odsn : (option) name of the output dataset (in WORK library); when not set, the input dataset idsn will be replaced with the new version with ordered variables; default: not set;olib : (option) name of the output library; by default: empty, i.e. ilib will be used in case odsn is set.Let us first consider test dataset #5:
| f | e | d | c | b | a |
|---|---|---|---|---|---|
| . | 1 | 2 | 3 | . | 5 |
then the variables in the dataset can be easily reordered alphabetically, e.g. using undifferently any of the instructions below:
so as to store in the output dataset dsn the following table:
| a | b | c | d | e | f |
|---|---|---|---|---|---|
| . | 1 | 2 | 3 | . | 5 |
Let us also consider test dataset #6:
| a | b | c | d | e | f | g | h |
|---|---|---|---|---|---|---|---|
| . | 1 | 2 | 3 | . | 5 | 6 | . |
the following instructions enable us to explicitely reorder the variables in the table (note that the variables not mentioned in varlst are retrieved from the remaining positions):
so that the output dataset dsn contains the table:
| b | a | h | e | c | d | f | h |
|---|---|---|---|---|---|---|---|
| 1 | . | . | . | 2 | 3 | 5 | . |
Instead, the instructions below allow us to order the variables according to their initial positions in the table:
so that the output dataset dsn contains the table:
| d | g | c | b | a | e | f | h |
|---|---|---|---|---|---|---|---|
| 3 | 6 | 2 | 1 | . | . | 5 | . |
It is also possible to order the variables in test dataset #6 according to the position of the same variables (i.e. same name) in test dataset #5:
which returns in the output dataset dsn the following table:
| f | e | d | c | b | a | g | h |
|---|---|---|---|---|---|---|---|
| 5 | . | 3 | 2 | 1 | . | 6 | . |
Run macro %_example_ds_order for more examples.
varlst is set (instead of varnum or varlike), the macro runs the following DATA step:idsn is already ordered as desired, the DATA step will still be ran as long as the output dataset odsn differs from idsn, so that a duplicated dataset is created.%ds_isempty, %lib_check, %var_check, %var_info, %var_rename.