Saving rows as separate files...

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

Saving rows as separate files...

Empi
Dear all,

I use SPSS for collecting and analysing text-based data. For example, in one
dataset each row corresponds to one newspaper article. To export these data
to another software, it would be great if each row (= article) could be
saved as separate file - preferably as *.txt file. Is that possible? Any
help would be highly appreciated -
Best,
empi



--
Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Saving rows as separate files...

Jon Peck
The easiest way to do this would be to first use the SPSSINC SPLIT DATASET extension command to make a batch of sav files in some new directory.  Then use SPSSINC PROCESS FILES to convert each of them to a text file.  The first step assumes that you have an id variable with unique values to use for splitting.  In the second step PROCESS FILES would open each file and save it as text or some other format using SAVE TRANSLATE.

I  can help further if needed if you want to go this way.

These extension commands can be installed from

On Wed, Dec 5, 2018 at 12:29 PM Empi <[hidden email]> wrote:
Dear all,

I use SPSS for collecting and analysing text-based data. For example, in one
dataset each row corresponds to one newspaper article. To export these data
to another software, it would be great if each row (= article) could be
saved as separate file - preferably as *.txt file. Is that possible? Any
help would be highly appreciated -
Best,
empi



--
Sent from: http://spssx-discussion.1045642.n5.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


--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Saving rows as separate files...

Empi
Dear Jon,

using this syntax works fine, it yields several separate *.sav files as
intended:

spssinc split dataset splitvar = county
/OUTPUT DIRECTORY=  "C:\Users\empisoz\Desktop\New" DELETECONTENTS = NO
FILENAME = "County_${county}_accounts"
/OPTIONS NAMES =VALUES PRINTLIST=YES .

However, I couldn't find examples how to implement the SPSSINC PROCESS FILES
/ SAVE TRANSLATE -
Can you help? The idea is still to arrive at a set of *.txt files...

Best,
Empi




--
Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Saving rows as separate files...

Jon Peck
Add FILELIST=filespec to the OPTIONS command to create an explicit list of files to process.  Suppose it is named files.txt and is in that same directory.

In SPSSINC PROCESS FILES, you specify at a minimum the input files via FILELIST (or a wildcard expression), the name of a syntax file to apply to each one, and where to write the Viewer file.

Something like this.
SPSSINC PROCESS FILES FILELIST="C:\Users\empisoz\Desktop\New\files.txt"
SYNTAX="C:\Users\empisoz\Desktop\New\export.sps"
VIEWERFILE="C:\Users\empisoz\Desktop\New\export.spv".


That will run export.sps on each file in files.txt.
The syntax in export.sps just opens the current file, constructs the name for the text output from the name of the input, and uses it in SAVE TRANSLATE.  It might look like this.  JOB_INPUTFILE is a file handle that is set by PROCESS FILES to the filespec of the current sav file.  The macro created by define looks a bit scary, but it just combines the output location, the base name of the sav file, and the .txt extension.

define !out () !quote(!concat(!unquote("C:\Users\empisoz\Desktop\New\")),
    !unquote(!eval(!JOB_DATAFILEROOT)), ".txt")) !enddefine.

GET FILE=JOB_INPUTFILE. 
SAVE OUTFILE=!out.

PROCESS FILES has a number of options that you can look into if needed by displaying the syntax help for the command.  You do this by running SPSSINC PROCESS FILES /HELP.  or by pressing F1 on an instance of it.
 


On Mon, Dec 10, 2018 at 6:24 AM Empi <[hidden email]> wrote:
Dear Jon,

using this syntax works fine, it yields several separate *.sav files as
intended:

spssinc split dataset splitvar = county
/OUTPUT DIRECTORY=  "C:\Users\empisoz\Desktop\New" DELETECONTENTS = NO
FILENAME = "County_${county}_accounts"
/OPTIONS NAMES =VALUES PRINTLIST=YES .

However, I couldn't find examples how to implement the SPSSINC PROCESS FILES
/ SAVE TRANSLATE -
Can you help? The idea is still to arrive at a set of *.txt files...

Best,
Empi




--
Sent from: http://spssx-discussion.1045642.n5.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


--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Saving rows as separate files...

Empi
...Jon, thank you very much - a related question: it is not possible to use
SPSSINC SPLIT DATASET directly in combination with file formats available in
SPSS (e.g. ASCII or Excel), or is it?
Best,
Empi



--
Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Saving rows as separate files...

Jon Peck
No.  SPLIT DATASET uses the XSAVE command, which allows individual cases to be written to different places, to do the work, and that command only writes sav files.

On Mon, Dec 10, 2018 at 10:40 PM Empi <[hidden email]> wrote:
...Jon, thank you very much - a related question: it is not possible to use
SPSSINC SPLIT DATASET directly in combination with file formats available in
SPSS (e.g. ASCII or Excel), or is it?
Best,
Empi



--
Sent from: http://spssx-discussion.1045642.n5.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


--
Jon K Peck
[hidden email]

===================== 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