lpad

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

lpad

Keval Khichadia
Hi,
I have a string variable ID (A10).
I need to add a leading 0 to the ID if it is 5 characters long. Otherwise I need to leave it as is. Is this possible.
For example,
S125678889 should be left as is
123567 should be left as is
12345 should be 012345.
I need to preserve the length of 10 for ID.
Thanks for any help.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: lpad

Katkowski, David
This should work for SPSS 16. I think the CHAR.LENTH function is
different for 15. May be LEN instead.

do if (CHAR.LENGTH(ID) = 5).
     compute ID = CONCAT("0",ID).
end if.
exe.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Keval Khichadia
Sent: Friday, June 27, 2008 3:47 PM
To: [hidden email]
Subject: lpad

Hi,
I have a string variable ID (A10).
I need to add a leading 0 to the ID if it is 5 characters long.
Otherwise I need to leave it as is. Is this possible.
For example,
S125678889 should be left as is
123567 should be left as is
12345 should be 012345.
I need to preserve the length of 10 for ID.
Thanks for any help.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: lpad

ViAnn Beadle
In reply to this post by Keval Khichadia
if (length(rtrim(id)) EQ 5) id=concat('0',id).




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Keval Khichadia
Sent: Friday, June 27, 2008 1:47 PM
To: [hidden email]
Subject: lpad

Hi,
I have a string variable ID (A10).
I need to add a leading 0 to the ID if it is 5 characters long. Otherwise I
need to leave it as is. Is this possible.
For example,
S125678889 should be left as is
123567 should be left as is
12345 should be 012345.
I need to preserve the length of 10 for ID.
Thanks for any help.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: lpad

Oliver, Richard
In reply to this post by Keval Khichadia
data list list (";") /ID (a10).
begin data
S125678889
123567
12345
end data.

*this works in version 16 or later.
do if char.length(id)=5.
compute id=concat("0", rtrim(id)).
end if.

*this works in all versions.
do if length(rtrim(id))=5.
compute id=concat("0", rtrim(id)).
end if.

list.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Keval Khichadia
Sent: Friday, June 27, 2008 2:47 PM
To: [hidden email]
Subject: lpad

Hi,
I have a string variable ID (A10).
I need to add a leading 0 to the ID if it is 5 characters long. Otherwise I need to leave it as is. Is this possible.
For example,
S125678889 should be left as is
123567 should be left as is
12345 should be 012345.
I need to preserve the length of 10 for ID.
Thanks for any help.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD