LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 23 Mar 2005 10:43:45 -0600
Reply-To:     "Marks, Jim" <>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         "Marks, Jim" <>
Subject:      Re: string to number
Content-Type: text/plain; charset="us-ascii"


You can use RENAME and DROP to get the names onto the numeric versions of the variables:

** sample data. DATA LIST FREE /var_1 var_2 var_3 (3A1). BEGIN DATA 1 2 3 0 0 0 1 2 1 3 0 0 0 0 5 END DATA.

** RECODE for new variables-- ADD with RENAME and DROP to clean file. RECODE var_1 TO var_3 (CONVERT) INTO nbr_1 to nbr_3. ADD FILES FILE = * /RENAME (var_1 TO var_3 = d1 TO d3) (nbr_1 TO nbr_3 = var_1 TO var_3) /DROP d1 to d3


Notice that I'm using "TO" in the variable lists-- my variables are in consecutive order in the file. If your variables are not consecutive, you will need to supply complete variable lists.


-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Hector Maletta Sent: Wednesday, March 23, 2005 10:17 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: string to number

However, I don't see why the RECODE solution is not acceptable, especially because you can recode all the variables at one stroke, as in: RECODE oldvariablelist (CONVERT) into newvariablelist.

If you choose your new variable names wisely you may not need to rename them back to the original variables' names. However, renaming is instantaneous and does not require a data pass, and so is DELETE VARIABLES. In older versions you delete variables through the /DROP or /KEEP subcommands in MATCH FILES or SAVE, which do require a data pass, but it is the same data pass used by the RECODE command, so no time is lost in that task (except the data pass may be a bit slower with more tasks to perform during the pass).


> -----Original Message----- > From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] > On Behalf Of Spousta Jan > Sent: Wednesday, March 23, 2005 12:45 PM > To: SPSSX-L@LISTSERV.UGA.EDU > Subject: Re: string to number > > > Hi, > > In the Variable View of the data editor, copy the word > Numeric (Ctrl-C) in the Type column and paste it into the > string columns (Ctrl-V) - it will convert them. > > Or write a macro if the syntax solution is needed. > > HTH > > Jan > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On > Behalf Of Benny Kong > Sent: Wednesday, March 23, 2005 4:42 PM > To: SPSSX-L@LISTSERV.UGA.EDU > Subject: string to number > > > Hi, > > I need to change a bunch of variables from string to numberic values. > > For example, > > Var1 (A1) > 0 > 1 > 0 > 1 > > To, > > Var1 (F1) > 0 > 1 > 0 > 1 > > > > NUMBER function or RECODE is handy. However, I can only think > of something as follows, > > recode var1 (convert) into var2. > delete var1. > rename var2 = var1. > exe. > > The codes above seem not that efficient. I was wondering if I > could do something directly (without creating an intermediate > variable). > > Thank you guys very much in advance. > > Benny >

Back to: Top of message | Previous page | Main SPSSX-L page