Trimming a numeric or string variables

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

Trimming a numeric or string variables

Khaleel Hussaini
Dear SPSS listers,

I have data that is coded in this fashion

bwt
7.08
8.00
9.05

I want this to appear as
bwt_1 bwt_2
7        08
8         00
9         05

Kh.

=====================
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
|

R: Trimming a numeric or string variables

Luca Meyer-3
Hi,

Assuming that your data are in a string variable and that all youe cases are
single digit before the period and with 2 decimals, try this:

string bwt_1 (a1) bwt_2 (a2).
compute bwt_1=substr(bwt,1,index(bwt,".")).
compute bwt_2=substr(bwt,index(bwt,".")+1).
exe.

Should they be in a numeric variable you can transform it to string first
and then run the same syntax.

HTH,
Luca

Mr. Luca MEYER
Market research, data analysis & more
www.lucameyer.com - Tel: +39.339.495.00.21


-----Messaggio originale-----
Da: SPSSX(r) Discussion [mailto:[hidden email]] Per conto di
Khaleel Hussaini
Inviato: venerdì 15 febbraio 2008 0.39
A: [hidden email]
Oggetto: Trimming a numeric or string variables

Dear SPSS listers,

I have data that is coded in this fashion

bwt
7.08
8.00
9.05

I want this to appear as
bwt_1 bwt_2
7        08
8         00
9         05

Kh.

=====================
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

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.20.5/1279 - Release Date: 14/02/2008
18.35


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.20.5/1279 - Release Date: 14/02/2008
18.35

=====================
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: Trimming a numeric or string variables

Carsten Pauck
In reply to this post by Khaleel Hussaini
 Hello Khaleel

*numeric vars.
compute bwt_1 = TRUNC(bwt) .
compute bwt_2 = bwt - bwt_1.

*convert to strings - if you want .
string bwt_1_1 (A8).
comp bwt_1_1 = ltrim(string(bwt_1,F5.0)) .

string bwt_1_2 (A8).
comp bwt_1_2 = substr(ltrim(string(bwt_2,F5.2)),2).
exe.

I hope this helps.

Carsten.



2008/2/15, Khaleel Hussaini <[hidden email]>:

>
> Dear SPSS listers,
>
> I have data that is coded in this fashion
>
> bwt
> 7.08
> 8.00
> 9.05
>
> I want this to appear as
> bwt_1 bwt_2
> 7        08
> 8         00
> 9         05
>
> Kh.
>
> =====================
> 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