write to mutiple text files

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

write to mutiple text files

David Millar
Dear All

I have a piece of syntax (see below) that I used (in the distant past) to write 30 separate text files based on an SPSS data file with 30 cases - one for each school, numbered 1-30 (variable 'schid').  Now, when I come back to it 9 years later, I find it does diddly squat.  I don't get my 30 files.  I don't even get an error message!

Any help would be greatly appreciated.

Regards

David Millar
ERC
Dublin

define !macro().

compute p=1.

!do !schid=1 !to 30.

do if (schid=p).

write outfile=!concat('school',!schid,'.txt')/ v1 to v5.

end if.

compute p=p+1.

execute.

!doend.

!enddefine.

!macro.
Reply | Threaded
Open this post in threaded view
|

Re: write to mutiple text files

Raynald Levesque
Hi

My guess is that the files were created but they are not in the folder where
you expect them.
Did you search you drive for file school1.txt?
You could spell out the path in the write command.

This is not important but note that the macro could be written as follows:

define !macro()
!do !schid=1 !to 30.
do if (schid=!schid).
write outfile=!concat('school',!schid,'.txt')/ v1 to v5.
end if.
execute.
!doend
!enddefine.

Cheers!

Raynald Levesque
www.spsstools.net

On 7/19/07, David Millar <[hidden email]> wrote:

>
> Dear All
>
> I have a piece of syntax (see below) that I used (in the distant past) to
> write 30 separate text files based on an SPSS data file with 30 cases - one
> for each school, numbered 1-30 (variable 'schid').  Now, when I come back to
> it 9 years later, I find it does diddly squat.  I don't get my 30 files.  I
> don't even get an error message!
>
> Any help would be greatly appreciated.
>
> Regards
>
> David Millar
> ERC
> Dublin
>
> define !macro().
>
> compute p=1.
>
> !do !schid=1 !to 30.
>
> do if (schid=p).
>
> write outfile=!concat('school',!schid,'.txt')/ v1 to v5.
>
> end if.
>
> compute p=p+1.
>
> execute.
>
> !doend.
>
> !enddefine.
>
> !macro.
>
Reply | Threaded
Open this post in threaded view
|

Re: write to mutiple text files

David Millar
In reply to this post by David Millar
Thanks to Karin, Jindra and Raynald.

Sure enough the syntax works when the path is included in the write command.  When I used this previously the syntax would just export the file to the same folder as the working file.  The version of the syntax Raynald forwarded is also neater than the original.

Best wishes

David