Importing csv files

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

Importing csv files

C Kirkman
1) Using syntax, is there a way to import a data file that is zipped? In
other words, unzip it on the fly so that I don't have to use a separate
program/step to unzip the file? The files are compressed using PKZip.

2) When importing a csv file, is it possible to specify that only certain
variables in a line (case) be brought in (eg, the first twenty variables
in a line, or variables 10-15, 20-25 and 36)?

I'm using the GET DATA command now. I looked at DATA LIST but didn't see
subcommands that would do either of these things.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Importing csv files

Marks, Jim
Not sure about number 1.

Number 2 is possible with GET DATA the format nX is valid (and results
in a skipped variable):

GET DATA  /TYPE = TXT
 /FILE = 'D:\mydata.csv'
 /DELCASE = LINE
 /DELIMITERS = " |"
 /ARRANGEMENT = DELIMITED
 /FIRSTCASE = 1
 /IMPORTCASE = FIRST 1000
 /VARIABLES =
 V1 A7
 V2 SDATE10
 V3 1X
 V4 A8
 V5 A5
 V6 f8.2
 V7 F1.0
.

This works with a valid file-- you might need to edit the specifications
to match your own file...
(mine has
        no variable names:
                /FIRSTCASE = 1
        uses the  |:
                DELIMITERS = " |'
        only brings in a sample of the data:
                /IMPORTCASE = FIRST 1000

--jim



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
C Kirkman
Sent: Tuesday, May 22, 2007 4:14 PM
To: [hidden email]
Subject: Importing csv files

1) Using syntax, is there a way to import a data file that is zipped? In
other words, unzip it on the fly so that I don't have to use a separate
program/step to unzip the file? The files are compressed using PKZip.

2) When importing a csv file, is it possible to specify that only
certain variables in a line (case) be brought in (eg, the first twenty
variables in a line, or variables 10-15, 20-25 and 36)?

I'm using the GET DATA command now. I looked at DATA LIST but didn't see
subcommands that would do either of these things.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Importing csv files

San K
In reply to this post by C Kirkman
1)
You can write DOS command to unzip the files (using pkzip/pkunzip).
PKZIP is free.
Eg:
CD C:\yourProjectDir\yourZippedDir\
C:\pkware\pkunzip -d *.zip
that will unzip all ziped files.

Then you can run SPSS through DOS again.
Eg: (This worked in SPSS 12)
cd c:\Program files\SPSS
runsyntx.exe C:\yourProjectDir\GetCSVfiles.sps

- San

On 5/23/07, C Kirkman <[hidden email]> wrote:

> 1) Using syntax, is there a way to import a data file that is zipped? In
> other words, unzip it on the fly so that I don't have to use a separate
> program/step to unzip the file? The files are compressed using PKZip.
>
> 2) When importing a csv file, is it possible to specify that only certain
> variables in a line (case) be brought in (eg, the first twenty variables
> in a line, or variables 10-15, 20-25 and 36)?
>
> I'm using the GET DATA command now. I looked at DATA LIST but didn't see
> subcommands that would do either of these things.
>
> Thanks
>
Reply | Threaded
Open this post in threaded view
|

Re: Importing csv files

C Kirkman
In reply to this post by C Kirkman
Thanks, two good solutions!