the corresponding new variable name. Multiple parenthesized groups of
variables may be specified.
-The @subcmd{DROP} subcommand deletes a specified list of variables from the
-active dataset.
+The @subcmd{DROP} subcommand deletes a specified list of variables
+from the active dataset. @cmd{MODIFY VARS} may not be used to delete
+all variables from the dictionary; use @cmd{NEW FILE} to do that
+(@pxref{NEW FILE}).
The @subcmd{KEEP} subcommand keeps the specified list of variables in the active
dataset. Any unlisted variables are deleted from the active dataset.
goto done;
}
}
- sort (&v[prev_nv], nv - prev_nv, sizeof *v,
- compare_variables_given_ordering, &ordering);
+
+ if (!ordering.positional)
+ sort (&v[prev_nv], nv - prev_nv, sizeof *v,
+ compare_variables_given_ordering, &ordering);
+ else if (!ordering.forward)
+ reverse_array(&v[prev_nv], nv - prev_nv, sizeof *v);
}
while (lex_token (lexer) != T_SLASH
&& lex_token (lexer) != T_ENDCMD);
goto done;
vm.drop_vars = drop_vars;
vm.n_drop = n_drop;
+
+ if (n_drop == dict_get_var_cnt (dataset_dict (ds)))
+ {
+ msg (SE, _("%s may not be used to delete all variables "
+ "from the active dataset dictionary. "
+ "Use %s instead."), "MODIFY VARS", "NEW FILE");
+ goto done;
+ }
}
else if (lex_match_id (lexer, "MAP"))
{
--- /dev/null
+dnl PSPP - a program for statistical analysis.
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl
+dnl This program is free software: you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation, either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+dnl
+AT_BANNER([MODIFY VARS])
+
+AT_SETUP([MODIFY VARS /REORDER])
+AT_KEYWORDS([REORDER])
+AT_DATA([modify-variables.sps], [dnl
+DATA LIST LIST /a b c x y z (F2.0).
+BEGIN DATA.
+1 2 3 4 5 6
+END DATA.
+
+MODIFY VARS /REORDER (z y x).
+DISPLAY INDEX.
+MODIFY VARS /REORDER (c b a).
+DISPLAY INDEX.
+
+MODIFY VARS /REORDER BACKWARD (z y x).
+DISPLAY INDEX.
+MODIFY VARS /REORDER BACKWARD (c b a).
+DISPLAY INDEX.
+
+MODIFY VARS /REORDER BACKWARD ALPHA (ALL).
+DISPLAY INDEX.
+MODIFY VARS /REORDER ALPHA (ALL).
+DISPLAY INDEX.
+])
+AT_CHECK([pspp -O format=csv modify-variables.sps], [0], [dnl
+Table: Reading free-form data from INLINE.
+Variable,Format
+a,F2.0
+b,F2.0
+c,F2.0
+x,F2.0
+y,F2.0
+z,F2.0
+
+Table: Variables
+Name,Position
+z,1
+y,2
+x,3
+a,4
+b,5
+c,6
+
+Table: Variables
+Name,Position
+c,1
+b,2
+a,3
+z,4
+y,5
+x,6
+
+Table: Variables
+Name,Position
+x,1
+y,2
+z,3
+c,4
+b,5
+a,6
+
+Table: Variables
+Name,Position
+a,1
+b,2
+c,3
+x,4
+y,5
+z,6
+
+Table: Variables
+Name,Position
+z,1
+y,2
+x,3
+c,4
+b,5
+a,6
+
+Table: Variables
+Name,Position
+a,1
+b,2
+c,3
+x,4
+y,5
+z,6
+])
+AT_CLEANUP
+
+AT_SETUP([MODIFY VARS /RENAME])
+AT_KEYWORDS([RENAME])
+AT_DATA([modify-variables.sps], [dnl
+DATA LIST LIST /a b c x y z (F2.0).
+BEGIN DATA.
+1 2 3 4 5 6
+END DATA.
+
+MODIFY VARS /RENAME (a b c = one two three).
+DISPLAY INDEX.
+MODIFY VARS /RENAME (one two three = a b c).
+DISPLAY INDEX.
+MODIFY VARS /RENAME (a = a).
+DISPLAY INDEX.
+MODIFY VARS /RENAME (a b c = b c a).
+DISPLAY INDEX.
+])
+AT_CHECK([pspp -O format=csv modify-variables.sps], [0], [dnl
+Table: Reading free-form data from INLINE.
+Variable,Format
+a,F2.0
+b,F2.0
+c,F2.0
+x,F2.0
+y,F2.0
+z,F2.0
+
+Table: Variables
+Name,Position
+one,1
+two,2
+three,3
+x,4
+y,5
+z,6
+
+Table: Variables
+Name,Position
+a,1
+b,2
+c,3
+x,4
+y,5
+z,6
+
+Table: Variables
+Name,Position
+a,1
+b,2
+c,3
+x,4
+y,5
+z,6
+
+Table: Variables
+Name,Position
+b,1
+c,2
+a,3
+x,4
+y,5
+z,6
+])
+AT_CLEANUP
+
+AT_SETUP([MODIFY VARS /DROP and /KEEP])
+AT_KEYWORDS([DROP KEEP])
+AT_DATA([modify-variables.sps], [dnl
+DATA LIST LIST /a b c x y z (F2.0).
+BEGIN DATA.
+1 2 3 4 5 6
+END DATA.
+
+MODIFY VARS /DROP a.
+DISPLAY INDEX.
+MODIFY VARS /KEEP ALL.
+DISPLAY INDEX.
+MODIFY VARS /KEEP c TO y.
+DISPLAY INDEX.
+MODIFY VARS /DROP x.
+DISPLAY INDEX.
+MODIFY VARS /KEEP y.
+DISPLAY INDEX.
+MODIFY VARS /DROP y.
+DISPLAY INDEX.
+])
+AT_CHECK([pspp -O format=csv modify-variables.sps], [1], [dnl
+Table: Reading free-form data from INLINE.
+Variable,Format
+a,F2.0
+b,F2.0
+c,F2.0
+x,F2.0
+y,F2.0
+z,F2.0
+
+Table: Variables
+Name,Position
+b,1
+c,2
+x,3
+y,4
+z,5
+
+Table: Variables
+Name,Position
+b,1
+c,2
+x,3
+y,4
+z,5
+
+Table: Variables
+Name,Position
+c,1
+x,2
+y,3
+
+Table: Variables
+Name,Position
+c,1
+y,2
+
+Table: Variables
+Name,Position
+y,1
+
+modify-variables.sps:16: error: MODIFY VARS: MODIFY VARS may not be used to delete all variables from the active dataset dictionary. Use NEW FILE instead.
+
+modify-variables.sps:17: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
+])
+AT_CLEANUP