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

LPAD and RTRIM?

595 views
Skip to first unread message

Clemens Böttcher

unread,
Apr 3, 2006, 1:14:37 PM4/3/06
to
Hello!

Does anyone have experience with the Syntax-command LPAD?
I´ll try to explain my difficulty:

There is data like this
120305
35031
120301
02051
etc.

The variable is a String-Variable (var1) and I want all data with 6
digits. If a string has only 5 digits (for example like 35031), I want
SPSS to attach a 0 at the beginning of the string (like 035031).

I´ve tried to first RTRIM it and then COMPUTE test=LPAD(var1,6,0), but
SPSS gave me a problem report.

Does anybody have an idea or maybe a solution?

Thank you for every kind of help,
Clemens


Jonathan Fry

unread,
Apr 3, 2006, 4:07:13 PM4/3/06
to

"Clemens Böttcher" <daf...@hotmail.com> wrote in message
news:e0rl8q$r21$1...@news1.nefonline.de...
The variable Var1 always has a length of six, even if you have assigned an
RTRIMmed string to it. Also, the third argument of LPAD must be a string,
not a number. You could use

COMPUTE TEST = LPAD(RTRIM(var1),6,'0').

or

IF (SUBSTR(var1,6,1) = ' ') SUBSTR(var1,6,1) = '0'.

Jonathan Fry
SPSS Inc.


Clemens Böttcher

unread,
Apr 4, 2006, 4:45:06 AM4/4/06
to
Thank you very much for your help!


"Jonathan Fry" <j...@spss.com.REMOVETHIS> schrieb im Newsbeitrag
news:e0rv0e$c81$1...@netsrv2.spss.com...

0 new messages