|
Hi Susan
The follwing automatically right align all string variables in the file.
DATA LIST LIST /str1(A12) nb(F2) str4(A4) nb2(F2) st19(A8).
BEGIN DATA
a 1 dd 2 jkjikkk
ab 2 a 3 uu
END DATA.
LIST.
DO REPEAT var=ALL.
DO IF LENGTH(var)>0.
COMPUTE var=LPAD(RTRIM(var),LENGTH(var)).
VARIABLE ALIGNMENT var(RIGHT).
END IF.
END REPEAT.
EXECUTE.
*FYI the command DO IF LENGTH(var)>0 generates an error when var is numeric
but this
not important. The syntax behaves as required.
Regards
Raynald Levesque rlevesque@videotron.ca
Visit my SPSS Pages http://pages.infinit.net/rlevesqu/index.htm
-----Original Message-----
From: Cardwell, Susan [mailto:susan.cardwell@mwsu.edu]
Sent: November 22, 2002 9:32 AM
To: 'Raynald Levesque'
Subject: RE: string variable WILL right justify (was 123)
Raynald,
Thanks so much for the syntax. Prior suggestions did not make use of LPAD. I
see that all i'm doing is transferring the padding from R to L. Simple. We
did not have this problem in spss 10.0. I have one other questions regarding
this process. I have many variables to right justify. In compute syntax
isn't it true that i can only COMPUTE one variable at a time? The majority
of my strings are A8 and I'd love to not have to write COMPUTE 60 times or
so.
Thank you,
Susan
PS. You're so clever and quick with your answers to the really hard
questions posed. Is this what you do for a living?
-----Original Message-----
From: Raynald Levesque [mailto:rlevesque@videotron.ca]
Sent: Thursday, November 21, 2002 6:49 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Cc: Cardwell, Susan
Subject: RE: string variable WILL right justify (was 123)
Hi Susan,
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 align.
In fact cells content are right align but the 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.
Have fun!
Raynald Levesque rlevesque@videotron.ca
Visit my SPSS Pages http://pages.infinit.net/rlevesqu/index.htm
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Cardwell, Susan
Sent: November 21, 2002 8:51 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: 123
folks,
we don't have a problem with importing excel into spss. the data is stable
and prior to spss version 11.5 the columns were fine. however, as i
mentioned in here before, with 11.5 the string variable columns will not
right justify. it's frustrating to cruise through the data looking for
patterns (unless i left justify, which is awkward because of the alpha
variable to its left), and spss has responded with the promise of a future
fix-it patch.
susan
|