Tuesday, 15 February 2011

Truncating a string variable & other things

This text has been copied from UCLA website!!!

Create a String Variable up that will be the name converted into upper case, lo that will be the name converted to lower case, and sub that will be the third through eighth character in the persons name. Note that we first had to use the string command to tell SPSS that up lo and sub are string variables that will have a length of up to 14 characters. Had we omitted the string command, these would have been treated as numeric variables, and when SPSS tried to assign a character value to the numeric variables, it would have generated an error. We also create len that is the length of the name variable, and len2

that is the length of the persons name.

STRING up lo (A14)
/sub (A6).

COMPUTE up = UPCASE(name).
COMPUTE lo = LOWER(name).
COMPUTE sub = SUBSTR(name,3,8).
COMPUTE len = LENGTH(name).

COMPUTE len2 = LENGTH(RTRIM(name)).

For more info visit: http://www.ats.ucla.edu/stat/spss/modules/functions.htm