Date: Tue, 7 Feb 2006 13:44:12 -0600
Reply-To: "Oliver, Richard" <roliver@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Oliver, Richard" <roliver@SPSS.COM>
Subject: Re: Convert many STRING vars to NUMERIC while keeping labels
Content-Type: text/plain; charset="us-ascii"
Yes, and with the programmability extension in SPSS 14, you can find and autorecode all the string variables:
*sample data.
data list free /numvar1 (f2) stringvar1 (a2) numvar2 (f2) stringvar2 (a2).
begin data
1 a 2 b
3 c 4 d
end data.
variable labels stringvar1 "This string variable"
stringvar2 "That string variable".
value labels stringvar1 "a" "Some label" "c" "Some other label"
/stringvar2 "b" "not a" "d" "not c".
*real job starts here.
begin program.
import spss
stringvarlist=[]
newvarlist=[]
varcount=spss.GetVariableCount()
for i in xrange(varcount):
if spss.GetVariableType(i)>0:
stringvarlist.append(spss.GetVariableName(i))
newvarlist.append("new_" + spss.GetVariableName(i))
spss.Submit("""
autorecode %s /into %s.
""" %(" ".join(stringvarlist), " ".join(newvarlist)))
end program.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Siraj Ur-rehman
Sent: Tuesday, February 07, 2006 1:19 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: Convert many STRING vars to NUMERIC while keeping labels
I used AUTORECODE command and worked fine for me.
Siraj
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
D. Michaels
Sent: Tuesday, February 07, 2006 2:06 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Convert many STRING vars to NUMERIC while keeping labels
Hi all,
I was wondering if anyone has had any success converting all STRING vars
in a file to NUMERIC format while retaining the value labels and
variable labels after the conversion. I am hoping that there is some
simply solution as a "destring" command, but I'm certain this doesn't
exist (from what I've reviewed).
I am attempting this conversion on a file which contains both string and
numeric variables (approx. 1000 variables in total). I've had some
success using various macros from spsstools.net including the varlist
macro and a macro which converts ALL string variables between 2 given
variables in the data file.
A combination of the two macros accomplishes a portion of the task, but
does not retain the variable or value lables. As well, the macros
seem
to work fine on a small set of variables, but seems to freeze when
running it on the entire file. I'm using SPSS 14.0 on a new P4 system
with 2 gig of memory which should be sufficient for the task.
Any help or suggestions would be GREATLY appreciated.
Sincerely,
D. Michaels