Re: loop and do repeat problem with thousands of unique values to insert

Posted by Albert-Jan Roskam on
URL: http://spssx-discussion.165.s1.nabble.com/loop-and-do-repeat-problem-with-thousands-of-unique-values-to-insert-tp4268902p4269982.html

;-)
Hmmm, the good ol' WRITE OUTFILE. I remember I generated 25 pages of IF statements and my colleague printed that syntax. *sigh* so many trees.

I wonder if there's a limit to the number of recodes within one RECODE though.
 
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: David Marso <[hidden email]>
To: [hidden email]
Sent: Tue, March 29, 2011 8:59:47 PM
Subject: Re: [SPSSX-L] loop and do repeat problem with thousands of unique values to insert

"or perhaps one big fat recode."
  RECODE would be the way to go rather than all those IF statements!
----------------------
That would likely work.  Kind of reminds me (in spirit)  of the "old school"
syntax generation/include  code I first inflicted upon the world in the
early 90's ;-)
recap  (may be wrong in details, but basic idea is as follows....
Since my version doesn't support Python ...In all likelihood this approach
(using python) will be more efficient than the wholesale butchery , the
match and aggregate mop-up of the file I suggested previously.

For historical reference only!  Can you believe this actually works (sort of
;-))))
OTOH:  I believe we have grown beyond it.
---------------------------------------------
GET FILE "REFERENCEMappingFILE".
DO IF $CASENUM=1.
WRITE OUTFILE 'OMG I cant believe Im posting this.txt'
  /"RECODE var01 TO var14 ".
END IF.
WRITE OUTFILE 'OMG I cant believe Im posting this.txt'
  /"  ("," '",strval,"'=", numvalue,")" .
DO IF $CASENUM=1.
WRITE OUTFILE 'OMG I cant believe Im posting this.txt'
  /"  INTO  newvar01 TO newvar14 ".
END IF.
Similar gobblygook for VALUE LABELS.
EXE.
GET FILE "bigfatfile".
INCLUDE  'OMG I cant believe Im posting this.txt'.
(or INSERT if that floats your boat more steady)....




Albert-Jan Roskam wrote:

>
> 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 = &quot;recode myvar &quot;
> for ch, num in mytable.iteritems():
>  recode += &quot;('%s'=%d) &quot;
> spss.Submit(recode + &quot;.\nexe.&quot;)
>
>  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 &lt;[hidden email]&gt;
> To: [hidden email]
> 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:
> &gt;
> &gt; dear fellow list visitors,
> &gt;
> &gt; please help me with this problem.
> &gt; I have the following syntax which works perfectly.
> &gt;
> &gt; It 'replaces' strings in old variables (name1 to name14) into
> &gt; numerical ones in a new variable (newname1 to newname14).
> &gt;
> &gt; example:
> &gt; vector name=name1 to name14.
> &gt; vector newname(14).
> &gt; loop i=1 to 14.
> &gt; do repeat a=&amp;quot;alpha&amp;quot; &amp;quot;beta&amp;quot;
> &amp;quot;gamma&amp;quot; / b=1 2
> &gt; 3.
> &gt; - if name(i) = a newname(i)=b.
> &gt; end repeat print.
> &gt; end loop.
> &gt;
> &gt;
> &gt; However, instead of three values (alpha beta and gamma) I have
> &gt; thousands of unique string values stored in a separate system file,
> &gt; each identified with a unique numerical code.
> &gt; How can I insert these values in the do repeat function (after 'a='
> &gt; and after 'b=')?
> &gt;
> &gt; The reason why I want to change these from string to numeric ones is
> &gt; that I know the system file will be smaller and hopefully also faster
> &gt; to read.
> &gt;
> &gt; You help is much appreciated.
> &gt;
> &gt; sincerely
> &gt; Maurice
> &gt;
> &gt;
> &gt;
> &gt;
> &gt; --
> &gt; ___________________________________________________________________
> &gt; Maurice Vergeer
> &gt; Department of communication, Radboud University�  (www.ru.nl)
> &gt; PO Box 9104, NL-6500 HE Nijmegen, The Netherlands
> &gt;
> &gt; Visiting Professor Yeungnam University, Gyeongsan, South Korea
> &gt;
> &gt; Recent publications:
> &gt; -Vergeer, M., Hermans, L., &amp;amp; Sams, S. (accepted for
> publication).
> &gt; Online social networks and micro-blogging in political campaigning:
> &gt; The exploration of a new campaign tool and a new campaign style.
> Party
> &gt; Politics.
> &gt; -Eisinga, R., Franses, Ph.H., &amp;amp; Vergeer, M. (2010). Weather
> conditions
> &gt; and daily television use in the Netherlands, 1996–2005. International
> &gt; Journal of Meteorology.
> &gt;
> &gt; Webspace
> &gt; www.mauricevergeer.nl
> > http://blog.mauricevergeer.nl/
> > www.journalisteninhetdigitaletijdperk.nl

> &gt; maurice.vergeer (skype)
> &gt; ___________________________________________________________________
> &gt;
> &gt; =====================
> &gt; To manage your subscription to SPSSX-L, send a message to
> &gt; [hidden email] (not to SPSSX-L), with no body text except
> the
> &gt; command. To leave the list, send the command
> &gt; SIGNOFF SPSSX-L
> &gt; For a list of commands to manage subscriptions, send the command
> &gt; INFO REFCARD
> &gt;
>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> &quot;When all else fails, RTFM.&quot;
>
> 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.html

>
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (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
>


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/loop-and-do-repeat-problem-with-thousands-of-unique-values-to-insert-tp4268902p4269934.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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