Date: Tue, 12 Feb 2002 11:38:58 -0500
Reply-To: Art@DrKendall.org
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Art Kendall <Arthur.Kendall@VERIZON.NET>
Subject: Re: Converting string variables to numeric
Content-Type: text/plain; charset=us-ascii
you show building the data, and defining the macro, but do you call the macro?
I don't have SPSS available any more since I retired, so I can't run your syntax.
The following untested syntax should show 2 ways do what you want IFF you are not trying to set up a production run.
What does it produce in the data view? In the variables view?
DATA LIST LIST /Q1(A8), Q2(A8), Q3(A8).
BEGIN DATA
12345678 12345678 12345678
12345678 12345678 12345678
12345678 12345678 12345678
12345678 12345678 12345678
END DATA.
LIST.
rename vars (q1 to q3 = s1 to s3).
numeric q1 to q3(f8).
do repeat s=s1 to s3 / q=q1 to q3.
compute q = numeric(s,f8).
end repeat.
list.
numeric x1 to x3 (f8).
recode s1 to s3 (convert) into x1 to x3.
list.
Grant Robertson wrote:
> Hello all.
>
> I'm trying to adapt a Marco set up by Raynald. I want to be able to convert all variables in the data file from string to numeric. The macro (below) runs with no error messages but does not convert the data from string to numeric. Any ideas as to why it might be doing this?
>
> Regards,
>
> Grant
>
> DATA LIST LIST /Q1(A8), Q2(A8), Q3(A8).
>
> BEGIN DATA
>
> 12345678 12345678 12345678
>
> 12345678 12345678 12345678
>
> 12345678 12345678 12345678
>
> 12345678 12345678 12345678
>
> END DATA.
>
> LIST.
>
> DEFINE !convert (vname=!TOKENS(1)
>
> /nformat=!TOKENS(1)
>
> /type=!TOKENS(1))
>
> !IF (!type='ss') !THEN
>
> STRING temp1234(!nformat).
>
> COMPUTE temp1234=!vname.
>
> !IFEND
>
> !IF (!type='ns') !THEN
>
> STRING temp1234(!nformat).
>
> COMPUTE temp1234=LTRIM(STRING(!vname,F18.0)).
>
> !IFEND
>
> !IF (!type='sn') !THEN
>
> COMPUTE temp1234=NUMBER(!vname,F18.0).
>
> FORMAT temp1234(!nformat).
>
> !IFEND
>
> MATCH FILES FILE=* /DROP=!vname.
>
> RENAME VARIABLE (temp1234=!vname).
>
> !Do !II = 1 !To 3
>
> !Let !Str1 = !Concat(q,!II)
>
> !convert vname =!Str1 nformat=F8.0 type=sn.
>
> !DoEnd
>
> !ENDDEFINE.
|