Differences between revisions 7 and 10 (spanning 3 versions)
Revision 7 as of 2021-10-01 15:33:23
Size: 2637
Comment:
Revision 10 as of 2021-11-24 15:33:10
Size: 2769
Comment:
Deletions are marked like this. Additions are marked like this.
Line 61: Line 61:
For an explanation on the syntax used on the `/variables` subcommand, see [[SPSSDataImport|here]]. If the data file has a header row, simply adjust the `/FIRSTCASE` subcommand to `2`.

For an explanation on the syntax used on the `/VARIABLES` subcommand, see [[SPSS/ReadingData|here]].
Line 80: Line 82:
== Tab-Delimited == == Tab-delimited ==
Line 96: Line 98:
For an explanation on the syntax used on the `/variables` subcommand, see [[SPSSDataImport|here]]. If the data file has a header row, simply adjust the `/FIRSTCASE` subcommand to `2`.

For an explanation on the syntax used on the `/VARIABLES` subcommand, see [[SPSS/ReadingData|here]].
Line 133: Line 137:
It is necessary to declare all variables, their widths, and their types on import. If the file has column headers, update the `/firstcase` subcommand.
For an explanation on the syntax used on the `/VARIABLES` subcommand, see [[SPSS/ReadingData|here]].

SPSS File I/O

SPSS is capable of handling most file formats, including proprietary ones.


Excel

To import from an Excel spreadsheet:

get data
  /type=xlsx
  /file="path/to/file"
  /sheet=name "Sheet1"
  /cellrange=full
  /readnames=on
  /assumedstrwidth=32767.

To export into an Excel spreadsheet:

save translate
  /outfile="path/to/file"
  /type=xlsx
  /version=12
  /map
  /replace
  /fieldnames
  /cells=values
  /keep=VARLIST.

It is not possible to export into an existing spreadsheet and add a sheet.


CSV

To import from a CSV file:

get data
  /type=txt
  /file="path/to/file"
  /delimiters=","
  /firstcase=1
  /importcase=all
  /variables=
  VAR1 A1
  VAR2 F2.

If the data file has a header row, simply adjust the /FIRSTCASE subcommand to 2.

For an explanation on the syntax used on the /VARIABLES subcommand, see here.

To export into a CSV file:

save translate
  /outfile="path/to/file"
  /type=csv
  /map
  /replace
  /fieldnames
  /cells=values
  /keep=VARLIST.


Tab-delimited

To import from a tab-delimited file:

get data
  /type=txt
  /file="path/to/file"
  /delimiters="\t"
  /firstcase=1
  /importcase=all
  /variables=
  VAR1 A1
  VAR2 F2.

If the data file has a header row, simply adjust the /FIRSTCASE subcommand to 2.

For an explanation on the syntax used on the /VARIABLES subcommand, see here.

To export into a tab-delimited file:

save translate
  /outfile="path/to/file"
  /type=tab
  /map
  /replace
  /fieldnames
  /cells=values
  /keep=VARLIST.


Fixed-width

To import from a fixed-width file:

get data
  /type=txt
  /file="path/to/file"
  /arrangement=fixed
  /fixcase=1
  /firstcase=1
  /importcase=all
  /variables=
  /1
  VAR1 0-2 A
  VAR2 3-5 F.

For an explanation on the syntax used on the /VARIABLES subcommand, see here.

To export into a fixed-width file:

write outfile="path/to/file"
  /1 VARLIST.


Stata

Note that inter-operability of Stata and SPSS is locked to specific versions. SPSS 22 is inter-operable with Stata 8 only.

There must also be considerations for metadata loss--Stata 8 has very low limits on variable and value labels.

To import from a Stata file:

get stata file="path/to/file".

To export into a Stata 8 SE file:

save translate
  /outfile="path/to/file"
  /type=stata
  /version=8
  /edition=se
  /map
  /replace
  /keep=VARLIST.


CategoryRicottone

SPSS/FileIO (last edited 2021-11-24 15:33:10 by DominicRicottone)