|
I am having trouble with left padding the numbers in a variable with zeroes to fill 12 character field. When I hit OK, there are no error messages, but nothing happens either. Since I couldn’t attach screen shots to this message, I have to explain it as best I can- can anyone see what I am doing wrong?
My syntax is COMPUTE test = LPAD(test,12,"0") . EXECUTE .
Variable view shows String , width 12, Left alignment, Nominal measure
Variable is ‘test’, and there are 15 cases- 000000000123 302 10 53 2 8952 40533 6125 56 31 9 114 060 08975 566
When I hit OK, it asks me if I want to change existing variable, I say yes, it runs, and nothing changes.
Vicki L. Stirkey Program Analyst 3 OMHSAS Office of Mental Health and Substance Abuse Services Division of Systems Management 717-705-8198 Fax: 717-772-6737
|
|
Hi Vicki,
I did a little digging because I thought your code should work and found this on Raynald's SPSS Tools site regarding strings in SPSS: *(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 means that you first have to trim the blanks that SPSS puts in there automatically. I don't know why it does this and that would be an interesting question to have answered by someone more knowledgeable than me on the list. Regardless...I tested the syntax below and it works... Take it easy, Ariel DATA LIST LIST /test (A12). BEGIN DATA 000000000123 302 10 53 2 8952 40533 6125 56 31 9 114 060 08975 566 END DATA. STRING Result (A12). COMPUTE Result=LPAD(RTRIM(test),12,'0'). EXECUTE . On Thu, May 21, 2009 at 3:22 PM, Stirkey, Vicki <[hidden email]> wrote: > > I am having trouble with left padding the numbers in a variable with zeroes to fill 12 character field. When I hit OK, there are no error messages, but nothing happens either. Since I couldn’t attach screen shots to this message, I have to explain it as best I can- can anyone see what I am doing wrong? > > > > My syntax is > > COMPUTE test = LPAD(test,12,"0") . > > EXECUTE . > > > > Variable view shows > > String , width 12, Left alignment, Nominal measure > > > > Variable is ‘test’, and there are 15 cases- > > 000000000123 > > 302 > > 10 > > 53 > > 2 > > 8952 > > 40533 > > 6125 > > 56 > > 31 > > 9 > > 114 > > 060 > > 08975 > > 566 > > > > > > When I hit OK, it asks me if I want to change existing variable, I say yes, it runs, and nothing changes. > > > > > > > > > > Vicki L. Stirkey > > Program Analyst 3 > > OMHSAS > > Office of Mental Health and Substance Abuse Services > > Division of Systems Management > > 717-705-8198 > > Fax: 717-772-6737 > > ===================== 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 |
|
Just another solution if SPSS16+ is used. I am using alter type command.
DATA LIST LIST /test (A12). BEGIN DATA 000000000123 302 10 53 2 8952 40533 6125 56 31 9 114 060 08975 566 END DATA. alter type test (f12). alter type test (n12). Martins 2009/5/22 Ariel Barak <[hidden email]>: > Hi Vicki, > > I did a little digging because I thought your code should work and > found this on Raynald's SPSS Tools site regarding strings in SPSS: > > *(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 means that you first have to trim the blanks that SPSS puts in > there automatically. I don't know why it does this and that would be > an interesting question to have answered by someone more knowledgeable > than me on the list. Regardless...I tested the syntax below and it > works... > > Take it easy, > Ariel > > DATA LIST LIST /test (A12). > BEGIN DATA > 000000000123 > 302 > 10 > 53 > 2 > 8952 > 40533 > 6125 > 56 > 31 > 9 > 114 > 060 > 08975 > 566 > END DATA. > > STRING Result (A12). > COMPUTE Result=LPAD(RTRIM(test),12,'0'). > EXECUTE . > > > On Thu, May 21, 2009 at 3:22 PM, Stirkey, Vicki <[hidden email]> wrote: >> >> I am having trouble with left padding the numbers in a variable with zeroes to fill 12 character field. When I hit OK, there are no error messages, but nothing happens either. Since I couldn't attach screen shots to this message, I have to explain it as best I can- can anyone see what I am doing wrong? >> >> >> >> My syntax is >> >> COMPUTE test = LPAD(test,12,"0") . >> >> EXECUTE . >> >> >> >> Variable view shows >> >> String , width 12, Left alignment, Nominal measure >> >> >> >> Variable is 'test', and there are 15 cases- >> >> 000000000123 >> >> 302 >> >> 10 >> >> 53 >> >> 2 >> >> 8952 >> >> 40533 >> >> 6125 >> >> 56 >> >> 31 >> >> 9 >> >> 114 >> >> 060 >> >> 08975 >> >> 566 >> >> >> >> >> >> When I hit OK, it asks me if I want to change existing variable, I say yes, it runs, and nothing changes. >> >> >> >> >> >> >> >> >> >> Vicki L. Stirkey >> >> Program Analyst 3 >> >> OMHSAS >> >> Office of Mental Health and Substance Abuse Services >> >> Division of Systems Management >> >> 717-705-8198 >> >> Fax: 717-772-6737 >> >> > > ===================== > 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 > -- Mārtiņš Liberts [hidden email] ===================== 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 |
|
Forgot to change back to string...
DATA LIST LIST /test (A12). BEGIN DATA 000000000123 302 10 53 2 8952 40533 6125 56 31 9 114 060 08975 566 END DATA. alter type test (f12). alter type test (n12). alter type test (a12). 2009/5/22 Mārtiņš Liberts <[hidden email]>: > Just another solution if SPSS16+ is used. I am using alter type command. > > > DATA LIST LIST /test (A12). > BEGIN DATA > 000000000123 > 302 > 10 > 53 > 2 > 8952 > 40533 > 6125 > 56 > 31 > 9 > 114 > 060 > 08975 > 566 > END DATA. > > alter type test (f12). > alter type test (n12). > > > Martins > > 2009/5/22 Ariel Barak <[hidden email]>: >> Hi Vicki, >> >> I did a little digging because I thought your code should work and >> found this on Raynald's SPSS Tools site regarding strings in SPSS: >> >> *(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 means that you first have to trim the blanks that SPSS puts in >> there automatically. I don't know why it does this and that would be >> an interesting question to have answered by someone more knowledgeable >> than me on the list. Regardless...I tested the syntax below and it >> works... >> >> Take it easy, >> Ariel >> >> DATA LIST LIST /test (A12). >> BEGIN DATA >> 000000000123 >> 302 >> 10 >> 53 >> 2 >> 8952 >> 40533 >> 6125 >> 56 >> 31 >> 9 >> 114 >> 060 >> 08975 >> 566 >> END DATA. >> >> STRING Result (A12). >> COMPUTE Result=LPAD(RTRIM(test),12,'0'). >> EXECUTE . >> >> >> On Thu, May 21, 2009 at 3:22 PM, Stirkey, Vicki <[hidden email]> wrote: >>> >>> I am having trouble with left padding the numbers in a variable with zeroes to fill 12 character field. When I hit OK, there are no error messages, but nothing happens either. Since I couldn't attach screen shots to this message, I have to explain it as best I can- can anyone see what I am doing wrong? >>> >>> >>> >>> My syntax is >>> >>> COMPUTE test = LPAD(test,12,"0") . >>> >>> EXECUTE . >>> >>> >>> >>> Variable view shows >>> >>> String , width 12, Left alignment, Nominal measure >>> >>> >>> >>> Variable is 'test', and there are 15 cases- >>> >>> 000000000123 >>> >>> 302 >>> >>> 10 >>> >>> 53 >>> >>> 2 >>> >>> 8952 >>> >>> 40533 >>> >>> 6125 >>> >>> 56 >>> >>> 31 >>> >>> 9 >>> >>> 114 >>> >>> 060 >>> >>> 08975 >>> >>> 566 >>> >>> >>> >>> >>> >>> When I hit OK, it asks me if I want to change existing variable, I say yes, it runs, and nothing changes. >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Vicki L. Stirkey >>> >>> Program Analyst 3 >>> >>> OMHSAS >>> >>> Office of Mental Health and Substance Abuse Services >>> >>> Division of Systems Management >>> >>> 717-705-8198 >>> >>> Fax: 717-772-6737 >>> >>> >> >> ===================== >> 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 >> > > > > -- > Mārtiņš Liberts > [hidden email] > -- Mārtiņš Liberts [hidden email] ===================== 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 |
| Free forum by Nabble | Edit this page |
