= SPSS Alter Type = The '''`ALTER TYPE`''' command changes the [[SPSS/DataTypes|data type]] of a variable. <> ---- == Uaage == {{{ alter type foo bar baz (F1.0). alter type ham (ADATE10) spam eggs (A10). }}} The '''`AMIN`''' and '''`AHEXMIN`''' keywords can be used to dynamically capture the minimum length a string variable can be set to without truncating data. For example: {{{ alter type all (a = amin). }}} Furthermore, basic arithmetic can be used with these keywords. `AMIN + 2` or `AMIN + 25%` set string lengths to the minimum required length plus 2 characters, or plus 25% of that length. To set formats conditionally, i.e. set `ADATE10` on variables that are formatted as `A10` but `ADATE11` on variables that are formatted as `A11`, try: {{{ alter type foo bar baz (A10 = ADATE10). alter type foo bar baz (A11 = ADATE11). }}} === Print === By default, SPSS will display the list of variables that were altered with the old and new formats. Add the '''`/PRINT=ALTEREDTYPES`''' subcommand to explicitly allow this behavior. To display the first 25 cases for which the alteration caused potentially lossy conversion (i.e. between string and numeric formats), add the '''`/PRINT=ALTEREDVALUES`''' subcommand. Not that `ALTEREDTYPES` and `ALTEREDVALUES` can be used together. To display nothing, add the '''`/PRINT=NONE`''' subcommand. ---- == Data Model == `ALTER TYPE` is executed immediately. If there are pending transformations, they are executed first. The active dataset is read ''only'' if there were pending transformations or if the `AMIN`/`AHEXMIN` keywords were used. ---- CategoryRicottone