Hi Maurice,
I'd store all the char-to-num translations of your reference file into one
Python dictionary and generate spss syntax based on that. It could be a long
list of IF statements, or perhaps one big fat recode.
I can help you with that if you want. I don't have spss on my laptop though, so
just let me know.Here's a first sketch:
import spss
cursor = spss.Cursor([0:2]). # char var and num codes in first and second column
mytable = dict([rec for rec in cursor.fetchall()]) # this may not be entirely
correct
cursor.close()
recode = "recode myvar "
for ch, num in mytable.iteritems():
recode += "('%s'=%d) "
spss.Submit(recode + ".\nexe.")
Cheers!!
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public
order, irrigation, roads, a fresh water system, and public health, what have the
Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
From: Bruce Weaver <bruce.weaver@hotmail.com>
To: SPSSX-L@LISTSERV.UGA.EDU
Sent: Tue, March 29, 2011 1:08:51 PM
Subject: Re: [SPSSX-L] loop and do repeat problem with thousands of unique
values to insert
Hi Maurice. Does AUTORECODE with /GROUP give you what you want?
AUTORECODE VARIABLES=name1 to name14
/INTO newname1 to newname14
/GROUP.
Maurice Vergeer wrote:
>
> dear fellow list visitors,
>
> please help me with this problem.
> I have the following syntax which works perfectly.
>
> It 'replaces' strings in old variables (name1 to name14) into
> numerical ones in a new variable (newname1 to newname14).
>
> example:
> vector name=name1 to name14.
> vector newname(14).
> loop i=1 to 14.
> do repeat a="alpha" "beta" "gamma" / b=1 2
> 3.
> - if name(i) = a newname(i)=b.
> end repeat print.
> end loop.
>
>
> However, instead of three values (alpha beta and gamma) I have
> thousands of unique string values stored in a separate system file,
> each identified with a unique numerical code.
> How can I insert these values in the do repeat function (after 'a='
> and after 'b=')?
>
> The reason why I want to change these from string to numeric ones is
> that I know the system file will be smaller and hopefully also faster
> to read.
>
> You help is much appreciated.
>
> sincerely
> Maurice
>
>
>
>
> --
> ___________________________________________________________________
> Maurice Vergeer
> Department of communication, Radboud University� (www.ru.nl)
> PO Box 9104, NL-6500 HE Nijmegen, The Netherlands
>
> Visiting Professor Yeungnam University, Gyeongsan, South Korea
>
> Recent publications:
> -Vergeer, M., Hermans, L., & Sams, S. (accepted for publication).
> Online social networks and micro-blogging in political campaigning:
> The exploration of a new campaign tool and a new campaign style. Party
> Politics.
> -Eisinga, R., Franses, Ph.H., & Vergeer, M. (2010). Weather conditions
> and daily television use in the Netherlands, 1996–2005. International
> Journal of Meteorology.
>
> Webspace
> www.mauricevergeer.nl
>
http://blog.mauricevergeer.nl/> www.journalisteninhetdigitaletijdperk.nl
> maurice.vergeer (skype)
> ___________________________________________________________________
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (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
>
-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/"When all else fails, RTFM."
NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/loop-and-do-repeat-problem-with-thousands-of-unique-values-to-insert-tp4268902p4269185.htmlSent from the SPSSX Discussion mailing list archive at Nabble.com.
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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