Read data into a spss datadocument from a CSV file by a script

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

Read data into a spss datadocument from a CSV file by a script

Frebus
I'm trying to read data form a CSV file into an spss datadocument by a
script. Up to now I have managed to open the CSV file and to put the data
in the datadocument by a syntax file which I start from the script. The
data need to be appended in an existing datadocument. I use the syntax:

Get DATA /Type = TXT
  /FILE = 'C:\Program Files\SPSS\decosoutput.csv'
  /DELCASE = Line
  /DELIMITERS = ";"
  /ARRANGEMENT = DELIMITED
  /FIRSTCASE = 1
  /IMPORTCASE = FIRST 1
  /VARIABLES = test1 F test2 F test3 F test4 F test5 F test6 F

The variables are placed at the right top of the datadocument. I want to
specify the location where the data need to be put in the script/syntax
files. How can I do that?
I now have the idea to make the variables in the sytax accesible for the
script... It did not work up to now. Or should I make a temporary
datadocument with the variables at the right top, and then make another
script to change the data positions?

I'm not very experienced at the programming, so any possible advise can
help me out! Please let me know what to do!

Since the amount of data it is not an option to do this manually.
Reply | Threaded
Open this post in threaded view
|

Re: Read data into a spss datadocument from a CSV file

Richard Ristow
A day for short answers, I guess.

At 06:01 AM 6/11/2007, Frebus wrote:


>I'm trying to read data form a CSV file into an spss datadocument by a
>script. Up to now I have managed to open the CSV file and to put the
>data in the datadocument by a syntax file which I start from the
>script.
>
>  The data need to be appended in an existing datadocument. I use the
> syntax:
>
>Get DATA /Type = TXT
>   /FILE = 'C:\Program Files\SPSS\decosoutput.csv'
>   /DELCASE = Line
>   /DELIMITERS = ";"
>   /ARRANGEMENT = DELIMITED
>   /FIRSTCASE = 1
>   /IMPORTCASE = FIRST 1
>   /VARIABLES = test1 F test2 F test3 F test4 F test5 F test6 F
>
>The variables are placed at the right top of the datadocument.

In fact, only the NEW data will be in this working file
('datadocument').

>I want to specify the location where the data need to be put in the
>script/syntax files. How can I do that? Should I make a temporary
>datadocument with the variables at the right top, and then make
>another script to change the data positions?

That's the way. If you want the new data at the end of the file, first
read the new data as you did above. Then use ADD FILES:

ADD FILES
   /FILE='OldData'
   /FILE=*.

SAVE OUTFILE='BothData'.

Replace 'OldData' and 'BothData' by the names of files you use,
including path.

If you want the new data somewhere in the middle of the new file, it'll
only work if you have your file sorted by certain variables, and want
the new data distributed so the new file is properly sorted.

In that case, after you read the new data,

SORT CASES BY FileKey.

ADD FILES
   /FILE='OldData'
   /FILE=*
   /BY FileKey.

SAVE OUTFILE='BothData'.

'FileKey' is the variable you want the final file sorted by. If it's
sorted by a set of variables, you can specify that set instead of the
single variable 'FileKey'.

-Good luck,
  Richard
Reply | Threaded
Open this post in threaded view
|

Re:Read data into a spss datadocument from a CSV file by a script

Jerabek Jindrich
In reply to this post by Frebus
Hi,

Do I have it right, you wont to change the order of variables in you datafile?

> The variables are placed at the right top of the datadocument. I want to
> specify the location where the data need to be put in the script/syntax
> files. How can I do that?

It can be done with any command that supports the "keep" subcomand, e.g. MATCH FILES, SAVE, GET...

MATCH FILES / file=* / keep = ListOfYourVarsInRequiredOrder .
it will rearrange variables in your datafile.

HTH
Jindra


> ------------ Původní zpráva ------------
> Od: Frebus <[hidden email]>
> Předmět: Read data into a spss datadocument from a CSV file by a script
> Datum: 11.6.2007 18:04:36
> ----------------------------------------
> I'm trying to read data form a CSV file into an spss datadocument by a
> script. Up to now I have managed to open the CSV file and to put the data
> in the datadocument by a syntax file which I start from the script. The
> data need to be appended in an existing datadocument. I use the syntax:
>
> Get DATA /Type = TXT
>   /FILE = 'C:\Program Files\SPSS\decosoutput.csv'
>   /DELCASE = Line
>   /DELIMITERS = ";"
>   /ARRANGEMENT = DELIMITED
>   /FIRSTCASE = 1
>   /IMPORTCASE = FIRST 1
>   /VARIABLES = test1 F test2 F test3 F test4 F test5 F test6 F
>
> The variables are placed at the right top of the datadocument. I want to
> specify the location where the data need to be put in the script/syntax
> files. How can I do that?
> I now have the idea to make the variables in the sytax accesible for the
> script... It did not work up to now. Or should I make a temporary
> datadocument with the variables at the right top, and then make another
> script to change the data positions?
>
> I'm not very experienced at the programming, so any possible advise can
> help me out! Please let me know what to do!
>
> Since the amount of data it is not an option to do this manually.
>
>
>