Break data file in SPSS

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

Break data file in SPSS

Winson Yeung
Dear all,

I want to break a SPSS data file with 1000 cases into small sessions of 40 consecutive cases each to run some models.  That is, sessions for case 1 - 40, case 2 - 41, case 3 - 42 and so on. Does anyone know how to write syntax commands to break the data and save them into seperate files? For example, file001.sav, file002.sav,..., etc.

Thanks & Regards,
Winson
Reply | Threaded
Open this post in threaded view
|

Re: Break data file in SPSS

Spousta Jan
Hi Winson,
Try  this way:

GET FILE='C:\Program Files\SPSS14\GSS93 subset.sav'.
compute auxvar = $casenum.


define subsets().
!do !i = 1 !to 11
!let !num = !i
* padding !num with zeros.
!if (!length(!num) !lt 3) !then !let !num = !concat("0", !num) !ifend
!if (!length(!num) !lt 3) !then !let !num = !concat("0", !num) !ifend

!let !name = !quote(!concat("C:\Program Files\SPSS14\file",!num,".sav"))

temp.
select if auxvar >= !i and auxvar < !i + 40.
save outfile = !name /drop auxvar /compress.

!doend
!enddefine.

subsets.

HTH

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Winson Yeung
Sent: Monday, October 16, 2006 9:17 AM
To: [hidden email]
Subject: Break data file in SPSS

Dear all,

I want to break a SPSS data file with 1000 cases into small sessions of
40 consecutive cases each to run some models.  That is, sessions for
case 1 - 40, case 2 - 41, case 3 - 42 and so on. Does anyone know how to
write syntax commands to break the data and save them into seperate
files? For example, file001.sav, file002.sav,..., etc.

Thanks & Regards,
Winson
Reply | Threaded
Open this post in threaded view
|

Re: Break data file in SPSS

Richard Ristow
In reply to this post by Winson Yeung
At 03:17 AM 10/16/2006, Winson Yeung wrote:

>I want to break a SPSS data file with 1000 cases into small sessions
>of 40 consecutive cases each to run some models.  That is, sessions
>for case 1 - 40, case 2 - 41, case 3 - 42 and so on. [I want to] save
>them into seperate files? For example, file001.sav, file002.sav,...,
>etc.

See, of course, Jan Spousta's solution.

If you want to run models on all the sessions, consider instead SPLIT
FILE, dividing the file into sessions that are then run separately by
the procedures.

Like this (not tested):

COMPUTE SESSION = 1 + TRUNC($CASENUM).
SPLIT FILE BY SESSION.