1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*(B) Does SPSS have a bug? String variables will not right align in the data editor.

*(A) Posted by Raynald Levesque to SPSSX-L on 2002/11/21.
* Say a variable str1 is an A8 string variable.
* When the value assigned to str1 has less than 8 characters, 
	SPSS pads the right of the string with blanks. This is why 
	when the "right align" feature of the variable is set, the 
	data editor does not *appear* to be right aligned. In fact 
	cells content are right aligned but blanks at the end 
	produce the wrong impression.

This is easy to fix as is shown by the following syntax:

DATA LIST LIST /str1(A8).
BEGIN DATA
a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
END DATA.
LIST.

COMPUTE str1=LPAD(RTRIM(str1),8).
VARIABLE ALIGNMENT str1(RIGHT).
EXECUTE.

*The compute statement removes any trailing blanks and replaces 
them by beginning blanks. That way, data are right align in the data viewer.