Date: Thu, 29 Jul 1999 22:00:08 -0400
Reply-To: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Raynald Levesque <rlevesque@VIDEOTRON.CA>
Subject: Re: help with syntax for creating files from subsets of original
Content-type: text/plain; charset=iso-8859-1
I offer a solution (not a perfect solution but a nevertheless solution)
FILE='C:\Program Files\SPSS\test\big file.sav'.
VARIABLES=vara /INTO vara_r
!DO !v=1 !TO !1.
SELECT IF (vara_r=!v).
SAVE OUTFILE=!QUOTE(!CONCAT('C:\Program Files\SPSS\test\filelev',!v,'.sav'))
/COMPRESSED /KEEP vara TO vard.
* Run up to here, look at number of levels of vara in Output then run next
line with 3 replaced by the number of levels.
1. in the syntax, replace the name and path of big file.sav by your name.
2. replace the path of the new files (see the line above the !DOEND),
replace "vara TO vard" by the applicable variables in your file.
3. run all but the last line of the syntax, look in the output window to
find out the number of levels of vara.
4. run the last line of the syntax replacing the 3 by the number found in 3.
If you do not want to verify the number of levels before running the last
line, then replace the 3 by a number which is large enough (for instance
100). If you have say only 25 levels, then fileslev25 to fileslev100 will be
Raynald Levesque firstname.lastname@example.org
----- Original Message -----
From: Daniel Sharp <dmsharp@MADISON.TEC.WI.US>
Sent: Thursday, July 29, 1999 2:50 PM
Subject: help with syntax for creating files from subsets of original file
> I have a large data file that needs to get divided into smaller data files
based on a value in one of the columns, lets say VarA. What I would like to
do is write some syntax that will first identify the values or levels in
VarA, then select observations from the original file based on the first
level, write these to a file called datalev1, then go on to the next value,
and looping/repeating this process until it has created a new file for each
level in VarA.
> I don't know from the outset how many different levels there are in VarA
and I want to avoid having to find out each time I run the syntax.
> Does anyone have any suggestions for approaching this problem?
> Example: Data is something like this:
> VarA VarB VarC VarD
> x 7 43 2
> x 8 22 4
> x 7 38 2
> y 8 27 3
> y 9 40 7
> z 8 25 5
> z 8 40 4
> z 7 32 6
> . . . .
> . . . .
> . . . .
> I want to create files, 1 for each level of VarA, with all the
observations with that level, and then name the subset file with a
meainingful name indicating the value of VarA that is included in the
smaller file. So for my example,
> make 3 files, datalevx, datalevy, datalevz with their corresponding
> Dan Sharp