Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

changing length of a string with Syntax SPSS 16

5,074 views
Skip to first unread message

baiyun

unread,
Jan 18, 2008, 9:26:50 AM1/18/08
to
Dear all,

I am testing SPSS 16, does anyone know how to change the length of a
string with syntax? According to SPSS, one can do that with syntax
(new features)

Thanks in advance!


Baiyun

Bruce Weaver

unread,
Jan 18, 2008, 12:55:07 PM1/18/08
to

I'd not heard this before, but your post prompted me to do a little
searching. The command you want is ALTER TYPE. Here is the Help file
entry for those who do not have v16.

------------- HELP for ALTER TYPE --------

Overview (ALTER TYPE command)

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
* You can use the TO keyword to specify a list of variables or the ALL
keyword to specify all variables in the active dataset.

* 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.

* 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.

* AMIN + n or AHEXMIN + n sets the width of string variables to the
minimum necessary width plus n bytes.

* 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

* All variables specified or implied in the variable list(s) must
exist in the active dataset.

* Each variable list must be followed by a format specification
enclosed in parentheses.

* Format specifications must be valid SPSS formats. For information on
valid format specifications, see Variable Types and Formats.

* If specified, the optional input format must be followed by an
equals sign and then the output format.

* 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

* 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.

* 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.

* Converting a numeric variable to string will result in truncated
values if the numeric value cannot be represented in the specified
string width.

* 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).

* The first ALTER TYPE command changes the formats of Numvar1 and
Numvar2 from F2 and F1 to F5.2 and F3.

* 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.

* 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.

* 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.

Related Topics
ALTER TYPE
PRINT Subcommand (ALTER TYPE command)

--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
"When all else fails, RTFM."

0 new messages