IBM SPSS Statistics 22 Command Syntax Reference

2 downloads 0 Views 53KB Size Report
v Command introduced. Example. ALTER TYPE StringDate1 to StringDate4 (Date11). ALTER TYPE ALL (A=AMIN). Overview. ALTER TYPE can be used to ...
ALTER TYPE ALTER TYPE varlist([input format = ] {output format }) [varlist...] {AMIN [+ [n[%]] } {AHEXMIN [+ [n[%]]} [/PRINT {[ALTEREDTYPES*] [ALTEREDVALUES]}] {NONE }

* Default if subcommand omitted. Release History Release 16.0 v Command introduced. Example ALTER TYPE StringDate1 to StringDate4 (Date11). ALTER TYPE ALL (A=AMIN).

Overview ALTER TYPE can be used to change the fundamental type (string or numeric) or format of variables, including changing the defined width of string variables. Options v You can use the TO keyword to specify a list of variables or the ALL keyword to specify all variables in the active dataset. v The optional input format specification restricts the type modification to only variables in the list that match the input format. If the input format doesn't include a width specification, all variables that match the basic format are included. An input format specification without a width specification includes all variables that match the basic format, regardless of defined width. v AMIN or AHEXMIN can be used as the output format specification to change the defined width of a string variable to the minimum width necessary to display all observed values of that variable without truncation. v AMIN + n or AHEXMIN + n sets the width of string variables to the minimum necessary width plus n bytes. v AMIN + n% or AHEXMIN + n% sets the width of string variables to the minimum necessary width plus n percent of that width. The result is rounded to an integer. Basic Specification The basic specification is the name of a variable in the active dataset followed by an output format specification enclosed in parentheses, as in: ALTER TYPE StringVar (A4).

Syntax Rules v All variables specified or implied in the variable list(s) must exist in the active dataset. v Each variable list must be followed by a format specification enclosed in parentheses. v Format specifications must be valid IBM SPSS Statistics formats. For information on valid format specifications, see “Variable Types and Formats” on page 48. v If specified, the optional input format must be followed by an equals sign and then the output format.

141

v If a variable is included in more than one variable list on the same ALTER TYPE command, only the format specification associated with the last instance of the variable name will be applied. (If you want to "chain" multiple modifications for the same variable, use multiple ALTER TYPE commands.) Operations v If the command does not include any AMIN or AHEXMIN format specifications and does not include ALTEREDVALUES on the PRINT subcommand, the command takes effect immediately. It does not read the active dataset or execute pending transformations. v If the command includes one or more AMIN or AHEXMIN format specifications or includes ALTEREDVALUES on the PRINT subcommand, the command reads the active dataset and causes execution of any pending transformations. v Converting a numeric variable to string will result in truncated values if the numeric value cannot be represented in the specified string width. v Converting a string variable to numeric will result in a system-missing value if the string contains characters that would be invalid for the specified numeric format. Examples DATA LIST FREE /Numvar1 (F2) Numvar2 (F1) StringVar1 (A20) StringVar2 (A30) StringDate1 (A11) StringDate2 (A10) StringDate3 (A10). BEGIN DATA 1 23 a234 b2345 28-Oct-2007 10/28/2007 10/29/2008 END DATA. ALTER TYPE Numvar1 (F5.2) Numvar2 (F3). ALTER TYPE StringDate1 to StringDate3 (A11 = DATE11). ALTER TYPE StringDate1 to StringDate3 (A10 = ADATE10). ALTER TYPE ALL (A=AMIN).

v The first ALTER TYPE command changes the formats of Numvar1 and Numvar2 from F2 and F1 to F5.2 and F3. v The next ALTER TYPE command converts all string variables between StringDate1 and StringDate3 (in file order) with a defined string width of 11 to the numeric date format DATE11 (dd-mmm-yyyy). The only variable that meets these criteria is StringDate1; so that is the only variable converted. v The third ALTER TYPE command converts all string variables between StringDate1 and StringDate3 with a defined string width of 10 to the numeric date format ADATE11 (mm/dd/yyyy). In this example, this conversion is applied to StringDate2 and StringDate3. v The last ALTER TYPE command changes the defined width of all remaining string variables to the minimum width necessary for each variable to avoid truncation of any values. In this example, StringVar1 changes from A20 to A4 and StringVar2 changes from A30 to A5. This command reads the data and executes any pending transformation commands.

PRINT Subcommand The optional PRINT subcommand controls the display of information about the variables modified by the ALTER TYPE command. The following options are available: ALTEREDTYPES. Display a list of variables for which the formats were changed and the old and new formats. This is the default. ALTEREDVALUES. Display a report of values that were changed if the fundamental type (string or numeric) was changed or the defined string width was changed. This report is limited to the first 25 values that were changed for each variable. NONE. Don't display any summary information. This is an alternative to ALTEREDTYPES and/or ALTEREDVALUES and cannot be used in combination with them.

142

IBM SPSS Statistics 22 Command Syntax Reference