Formating a String Variable

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

Formating a String Variable

Ucal Gyam
Dear List,
I have a dataset with a string variable Var1.
Var1
0
7.41
0.21
1.5
65.12
0.7
23
I will like to create a new variable (string or numeric) with the format below.

Var2
000000
007.41
000.21
0001.5
065.12
0000.7
000023

Any ideas on how this can be accomplished will be very welcome.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: Formating a String Variable

Richard Ristow
At 02:04 PM 4/27/2007, Ucal Gyam wrote:

>I have a string variable Var1.
>Var1
>0
>7.41
>0.21
>1.5
>65.12
>0.7
>23
>I will like to create a new variable (string or numeric) with the
>format below.
>
>Var2
>000000
>007.41
>000.21
>0001.5
>065.12
>0000.7
>000023

It has to be a string variable, I think; probably should be, in any
case. Try this (SPSS 15 draft output):


|-----------------------------|---------------------------|
|Output Created               |27-APR-2007 15:07:24       |
|-----------------------------|---------------------------|
var1

0
7.41
0.21
1.5
65.12
0.7
23

Number of cases read:  7    Number of cases listed:  7


STRING   var2 (A10).
COMPUTE  var2 = LPAD(LTRIM(RTRIM(var1)),6,'0').
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |27-APR-2007 15:07:25       |
|-----------------------------|---------------------------|
var1    var2

0       000000
7.41    007.41
0.21    000.21
1.5     0001.5
65.12   065.12
0.7     0000.7
23      000023

Number of cases read:  7    Number of cases listed:  7
===================
APPENDIX: Test data
===================
*  ................................................................. .
*  .................   Test data               ..................... .
DATA LIST FIXED SKIP=1
   /var1  04-10 (A).
BEGIN DATA
----|---10----|---20
*  0
*  7.41
*  0.21
*  1.5
*  65.12
*  0.7
*  23
END DATA.
Reply | Threaded
Open this post in threaded view
|

Re: Formating a String Variable

Ucal Gyam
In reply to this post by Ucal Gyam
Hi  Richard,
Thanks, you have solved my problem for me.


----- Original Message ----
From: Richard Ristow <[hidden email]>
To: Ucal Gyam <[hidden email]>; [hidden email]
Sent: Friday, April 27, 2007 3:17:36 PM
Subject: Re: Formating a String Variable


At 02:04 PM 4/27/2007, Ucal Gyam wrote:

>I have a string variable Var1.
>Var1
>0
>7.41
>0.21
>1.5
>65.12
>0.7
>23
>I will like to create a new variable (string or numeric) with the
>format below.
>
>Var2
>000000
>007.41
>000.21
>0001.5
>065.12
>0000.7
>000023

It has to be a string variable, I think; probably should be, in any
case. Try this (SPSS 15 draft output):


|-----------------------------|---------------------------|
|Output Created               |27-APR-2007 15:07:24       |
|-----------------------------|---------------------------|
var1

0
7.41
0.21
1.5
65.12
0.7
23

Number of cases read:  7    Number of cases listed:  7


STRING   var2 (A10).
COMPUTE  var2 = LPAD(LTRIM(RTRIM(var1)),6,'0').
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |27-APR-2007 15:07:25       |
|-----------------------------|---------------------------|
var1    var2

0       000000
7.41    007.41
0.21    000.21
1.5     0001.5
65.12   065.12
0.7     0000.7
23      000023

Number of cases read:  7    Number of cases listed:  7
===================
APPENDIX: Test data
===================
*  ................................................................. .
*  .................   Test data               ..................... .
DATA LIST FIXED SKIP=1
   /var1  04-10 (A).
BEGIN DATA
----|---10----|---20
*  0
*  7.41
*  0.21
*  1.5
*  65.12
*  0.7
*  23
END DATA.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com