Convert all for Numeric Type

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

Convert all for Numeric Type

Carlos Renato-2
Dear Friends of List

I have a list of n variables of the type
"string" and I would like to convert all for
numeric type. Currently I use this macro below,
case knows you a method faster waits return.

SET MPRINT OFF.
SET WORKSPACE=500000.
DEFINE MacroStringforNumeric (DiretorioAnalise=!TOKENS(1)/
variaveis=!CMDEND)
INCLUDE !DiretorioAnalise+!QUOTE('\')+"NomesVariaveisNumericas.sps".
!DO !VarOriginal !IN (!variaveis)
NUMERIC Temporaria(F20.4).
COMPUTE Temporaria=NUMBER(!VarOriginal,F20.0).
MATCH FILES FILE=* /DROP=!VarOriginal.
RENAME VARIABLE (Temporaria=!VarOriginal).
!DOEND.
!ENDDEFINE.

Where NomesVariaveisNumericas is a list in macro form.

Carlos Renato
Statistician
+55 81.35811246
Reply | Threaded
Open this post in threaded view
|

Re: Convert all for Numeric Type

Hector Maletta
Prezado Carlos Renato,
Why don't you use the CONVERT keyword in the RECODE command? Example:
RECODE string1 string2 string3 (CONVERT) INTO num1 num2 num3.
Looks easier to me. Of course, you would have to write down the (probably
long) list of old string variables and new numeric variables, which may take
time, but you would have to put these lists also into your macro, so no
extra labor lost on that account.
To save time, the list of the old string variables can be easily copied into
the syntax window from the variable information dialog box, and the new
numeric variables might be just a slight variation of the old names.
Saudaçoes.
Hector


-----Mensaje original-----
De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de
Carlos Renato
Enviado el: Thursday, August 17, 2006 2:58 PM
Para: [hidden email]
Asunto: Convert all for Numeric Type

Dear Friends of List

I have a list of n variables of the type
"string" and I would like to convert all for
numeric type. Currently I use this macro below,
case knows you a method faster waits return.

SET MPRINT OFF.
SET WORKSPACE=500000.
DEFINE MacroStringforNumeric (DiretorioAnalise=!TOKENS(1)/
variaveis=!CMDEND)
INCLUDE !DiretorioAnalise+!QUOTE('\')+"NomesVariaveisNumericas.sps".
!DO !VarOriginal !IN (!variaveis)
NUMERIC Temporaria(F20.4).
COMPUTE Temporaria=NUMBER(!VarOriginal,F20.0).
MATCH FILES FILE=* /DROP=!VarOriginal.
RENAME VARIABLE (Temporaria=!VarOriginal).
!DOEND.
!ENDDEFINE.

Where NomesVariaveisNumericas is a list in macro form.

Carlos Renato
Statistician
+55 81.35811246
Reply | Threaded
Open this post in threaded view
|

Re:Convert all for Numeric Type

Jerabek Jindrich
In reply to this post by Carlos Renato-2
Hello,

A macro is not a must to convert strings to numerics. Syntax is sufficient(!not tested):
DO REPEAT
oldV = Str1 to StrN /*use 'to convention' if variables are contiguos in your datafile, if not write down all your string variables*/
/newV = Num1 to NumN .
COMPUTE newV = NUMBER(oldV,F20.0).
END REPEAT.

IMO the repeated command 'MATCH FILES/drop' makes the macro to run slowly. In case you realy wish to drop the old vars it can be done in one step:
MATCH FILES / file=* /drop Str1 to strN .
RENAME VAR (Num1 to NumN = Str1 to StrN).

HTH
Jindra


> ------------ Původní zpráva ------------
> Od: Carlos Renato <[hidden email]>
> Předmět: Convert all for Numeric Type
> Datum: 17.8.2006 19:59:09
> ----------------------------------------
> Dear Friends of List
>
> I have a list of n variables of the type
> "string" and I would like to convert all for
> numeric type. Currently I use this macro below,
> case knows you a method faster waits return.
>
> SET MPRINT OFF.
> SET WORKSPACE=500000.
> DEFINE MacroStringforNumeric (DiretorioAnalise=!TOKENS(1)/
> variaveis=!CMDEND)
> INCLUDE !DiretorioAnalise+!QUOTE('\')+"NomesVariaveisNumericas.sps".
> !DO !VarOriginal !IN (!variaveis)
> NUMERIC Temporaria(F20.4).
> COMPUTE Temporaria=NUMBER(!VarOriginal,F20.0).
> MATCH FILES FILE=* /DROP=!VarOriginal.
> RENAME VARIABLE (Temporaria=!VarOriginal).
> !DOEND.
> !ENDDEFINE.
>
> Where NomesVariaveisNumericas is a list in macro form.
>
> Carlos Renato
> Statistician
> +55 81.35811246
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Convert all for Numeric Type

Art Kendall
In reply to this post by Carlos Renato-2
How are you bringing the data into SPSS at first?

Art

Carlos Renato wrote:

> Dear Friends of List
>
> I have a list of n variables of the type
> "string" and I would like to convert all for
> numeric type. Currently I use this macro below,
> case knows you a method faster waits return.
>
> SET MPRINT OFF.
> SET WORKSPACE=500000.
> DEFINE MacroStringforNumeric (DiretorioAnalise=!TOKENS(1)/
> variaveis=!CMDEND)
> INCLUDE !DiretorioAnalise+!QUOTE('\')+"NomesVariaveisNumericas.sps".
> !DO !VarOriginal !IN (!variaveis)
> NUMERIC Temporaria(F20.4).
> COMPUTE Temporaria=NUMBER(!VarOriginal,F20.0).
> MATCH FILES FILE=* /DROP=!VarOriginal.
> RENAME VARIABLE (Temporaria=!VarOriginal).
> !DOEND.
> !ENDDEFINE.
>
> Where NomesVariaveisNumericas is a list in macro form.
>
> Carlos Renato
> Statistician
> +55 81.35811246
>
>
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Missing create function in version 14 after update to 14.1

Roberts, Michael
In reply to this post by Carlos Renato-2
Hi All,

Has anyone experienced a loss of the 'Create' function in version 14
after updating with 14.01 and/or installing the programmability plug in
for Python?

I cannot say whether this occurred prior to the Python plug-in being
installed, but my attempts to use the create function result in the
following error (copied exactly from the output - I did not put in the
forward slash after 'en' in the path!)  :


"Warnings
Command name: CREATE
Undefined error #15676 - not found in file "c:\program
files\spss_v14\en/windows\spss.err"
This command not executed. "

Thanks for any advice in advance.

Mike
Reply | Threaded
Open this post in threaded view
|

Re: Missing create function in version 14 after update to 14.1

Peck, Jon
This message is missing from the error file, but it reads as follows.

    There are too many cases to fit into memory at one time.
    If multiple result variables are being generated, you can
    reduce the memory requirements by breaking up the problem
    into multiple procedure invocations.  Otherwise, use
    SET WORKSPACE to increase the memory available.

Sorry.  This has been filed in our bug database.

Regards,
Jon Peck
SPSS

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Roberts, Michael
Sent: viernes, 18 de agosto de 2006 7:47
To: [hidden email]
Subject: [SPSSX-L] Missing create function in version 14 after update to 14.1

Hi All,

Has anyone experienced a loss of the 'Create' function in version 14
after updating with 14.01 and/or installing the programmability plug in
for Python?

I cannot say whether this occurred prior to the Python plug-in being
installed, but my attempts to use the create function result in the
following error (copied exactly from the output - I did not put in the
forward slash after 'en' in the path!)  :


"Warnings
Command name: CREATE
Undefined error #15676 - not found in file "c:\program
files\spss_v14\en/windows\spss.err"
This command not executed. "

Thanks for any advice in advance.

Mike