lpad

View: New views
4 Messages — Rating Filter:   Alert me  

lpad

by Keval Khichadia :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
LISTSERV@... (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

Re: lpad

by Katkowski, David :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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:SPSSX-L@...] On Behalf Of
Keval Khichadia
Sent: Friday, June 27, 2008 3:47 PM
To: SPSSX-L@...
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
LISTSERV@... (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
LISTSERV@... (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

Re: lpad

by ViAnn Beadle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

if (length(rtrim(id)) EQ 5) id=concat('0',id).




-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@...] On Behalf Of
Keval Khichadia
Sent: Friday, June 27, 2008 1:47 PM
To: SPSSX-L@...
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
LISTSERV@... (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
LISTSERV@... (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

Re: lpad

by Oliver, Richard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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:SPSSX-L@...] On Behalf Of Keval Khichadia
Sent: Friday, June 27, 2008 2:47 PM
To: SPSSX-L@...
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
LISTSERV@... (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
LISTSERV@... (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
LightInTheBox - Buy quality products at wholesale price!