Need help with SPSS scripting

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

Need help with SPSS scripting

Malanding Jaiteh
I am trying to import several 1000  ascii (*.TXT ) raster files into
into single variable SPSS files (syntax below for 1 file). I am new to
SPSS scripting so I am looking for samples (basic or vb) that I can
learn from?

Thanks,
Malanding Jaiteh


GET DATA
  /TYPE=TXT
  /FILE='G:\*2.txt'
  /DELCASE=VARIABLES 1
  /DELIMITERS="\t "
  /ARRANGEMENT=DELIMITED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  Variable1 F13.3.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.
SAVE OUTFILE='G:\*2.sav'
  /COMPRESSED.

=====================
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: Need help with SPSS scripting

Art Kendall
if there is an identifier in each .txt file that tells you which .txt
file it is,  or
if this is a highly unusual situation, and you don't need to go back to
the .txt data during data prep,
you can use the copy command from your OS.
For example,  in Windows put all of the files in one folder. Go to the
command prompt. Navigate to the folder.
In teh command prompt window type copy *.txt all.asc.
Exit the command prompt.
Use explorer to go to the folder.  Move all.asc to the place you want
it.  Rename it to .txt or just read it in as .asc.

How are you using the word raster?  I would usually associate it with
binary or jpeg type data.

Scripts are now considered by many to be obsolete, you may want to stick
with syntax and use Python to generlize.

If this does not meet your needs please repost and ask specifically
about using python.

Art Kendall
Social Research Consultants

On 6/28/2010 10:31 AM, Malanding Jaiteh wrote:

> I am trying to import several 1000  ascii (*.TXT ) raster files into
> into single variable SPSS files (syntax below for 1 file). I am new to
> SPSS scripting so I am looking for samples (basic or vb) that I can
> learn from?
>
> Thanks,
> Malanding Jaiteh
>
>
> GET DATA
>  /TYPE=TXT
>  /FILE='G:\*2.txt'
>  /DELCASE=VARIABLES 1
>  /DELIMITERS="\t "
>  /ARRANGEMENT=DELIMITED
>  /FIRSTCASE=1
>  /IMPORTCASE=ALL
>  /VARIABLES=
>  Variable1 F13.3.
> CACHE.
> EXECUTE.
> DATASET NAME DataSet1 WINDOW=FRONT.
> SAVE OUTFILE='G:\*2.sav'
>  /COMPRESSED.
>
> =====================
> 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
>

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Need help with SPSS scripting

Albert-Jan Roskam
There may be an easier way, without looping, but:
 
import glob, os, csv
def mergeCsv(outfilename = "d:/merged.tab", silent = True, header = True):
    try:
        os.remove(outfilename)
    except OSError:
        pass
    f_out = open(outfilename, "ab")
    csv_writer = csv.writer(f_out)
    for n, tab in enumerate(glob.glob("d:/temp/*.tab")):
        if not silent:
            print "... Processing file %s: %s" % (n+1, tab)
        csv_reader = csv.reader(open(tab, "rb"))
        if header:
            header = csv_reader.next()
        for line in csv_reader:
            csv_writer.writerow(line)
    f_out.close()
mergeCsv(silent = False)


Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 6/28/10, Art Kendall <[hidden email]> wrote:

From: Art Kendall <[hidden email]>
Subject: Re: [SPSSX-L] Need help with SPSS scripting
To: [hidden email]
Date: Monday, June 28, 2010, 5:58 PM

if there is an identifier in each .txt file that tells you which .txt
file it is,  or
if this is a highly unusual situation, and you don't need to go back to
the .txt data during data prep,
you can use the copy command from your OS.
For example,  in Windows put all of the files in one folder. Go to the
command prompt. Navigate to the folder.
In teh command prompt window type copy *.txt all.asc.
Exit the command prompt.
Use explorer to go to the folder.  Move all.asc to the place you want
it.  Rename it to .txt or just read it in as .asc.

How are you using the word raster?  I would usually associate it with
binary or jpeg type data.

Scripts are now considered by many to be obsolete, you may want to stick
with syntax and use Python to generlize.

If this does not meet your needs please repost and ask specifically
about using python.

Art Kendall
Social Research Consultants

On 6/28/2010 10:31 AM, Malanding Jaiteh wrote:

> I am trying to import several 1000  ascii (*.TXT ) raster files into
> into single variable SPSS files (syntax below for 1 file). I am new to
> SPSS scripting so I am looking for samples (basic or vb) that I can
> learn from?
>
> Thanks,
> Malanding Jaiteh
>
>
> GET DATA
>  /TYPE=TXT
>  /FILE='G:\*2.txt'
>  /DELCASE=VARIABLES 1
>  /DELIMITERS="\t "
>  /ARRANGEMENT=DELIMITED
>  /FIRSTCASE=1
>  /IMPORTCASE=ALL
>  /VARIABLES=
>  Variable1 F13.3.
> CACHE.
> EXECUTE.
> DATASET NAME DataSet1 WINDOW=FRONT.
> SAVE OUTFILE='G:\*2.sav'
>  /COMPRESSED.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@... (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
>

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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: Need help with SPSS scripting

Art Kendall
In reply to this post by Art Kendall
Similar questions have appeared on this list. I suggest you check the archives from this list at
http://listserv.uga.edu/archives/spssx-l.html

There should also be info there on "devcentral".

Art

On 6/28/2010 1:11 PM, Ramón López wrote:
Hello Sirs:
Thanks you very much for you support in advance.
Please could you indicate me a good references to learn to use Python with SPSS?
Best Regards

Ingº. Ramon Lopez (58)-412-8318409
Chat Skype: lopeznomar
Contactame Twitter


2010/6/28 Art Kendall <[hidden email]>
if there is an identifier in each .txt file that tells you which .txt
file it is,  or
if this is a highly unusual situation, and you don't need to go back to
the .txt data during data prep,
you can use the copy command from your OS.
For example,  in Windows put all of the files in one folder. Go to the
command prompt. Navigate to the folder.
In teh command prompt window type copy *.txt all.asc.
Exit the command prompt.
Use explorer to go to the folder.  Move all.asc to the place you want
it.  Rename it to .txt or just read it in as .asc.

How are you using the word raster?  I would usually associate it with
binary or jpeg type data.

Scripts are now considered by many to be obsolete, you may want to stick
with syntax and use Python to generlize.

If this does not meet your needs please repost and ask specifically
about using python.

Art Kendall
Social Research Consultants


On 6/28/2010 10:31 AM, Malanding Jaiteh wrote:
I am trying to import several 1000  ascii (*.TXT ) raster files into
into single variable SPSS files (syntax below for 1 file). I am new to
SPSS scripting so I am looking for samples (basic or vb) that I can
learn from?

Thanks,
Malanding Jaiteh


GET DATA
 /TYPE=TXT
 /FILE='G:\*2.txt'
 /DELCASE=VARIABLES 1
 /DELIMITERS="\t "
 /ARRANGEMENT=DELIMITED
 /FIRSTCASE=1
 /IMPORTCASE=ALL
 /VARIABLES=
 Variable1 F13.3.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.
SAVE OUTFILE='G:\*2.sav'
 /COMPRESSED.

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


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

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Need help with SPSS scripting

mpirritano

Raynald Levesque’s book:

 

http://www.spss.com/sites/dm-book/

 

very good intro.

 

Matthew Pirritano, Ph.D.

Research Analyst IV

Medical Services Initiative (MSI)

Orange County Health Care Agency

(714) 568-5648


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Wednesday, June 30, 2010 6:33 AM
To: [hidden email]
Subject: Re: Need help with SPSS scripting

 

Similar questions have appeared on this list. I suggest you check the archives from this list at
http://listserv.uga.edu/archives/spssx-l.html

There should also be info there on "devcentral".

Art

On 6/28/2010 1:11 PM, Ramón López wrote:

Hello Sirs:
Thanks you very much for you support in advance.
Please could you indicate me a good references to learn to use Python with SPSS?
Best Regards

Ingº. Ramon Lopez (58)-412-8318409

Chat Skype: lopeznomar

Contactame Twitter

 

2010/6/28 Art Kendall <[hidden email]>

if there is an identifier in each .txt file that tells you which .txt
file it is,  or
if this is a highly unusual situation, and you don't need to go back to
the .txt data during data prep,
you can use the copy command from your OS.
For example,  in Windows put all of the files in one folder. Go to the
command prompt. Navigate to the folder.
In teh command prompt window type copy *.txt all.asc.
Exit the command prompt.
Use explorer to go to the folder.  Move all.asc to the place you want
it.  Rename it to .txt or just read it in as .asc.

How are you using the word raster?  I would usually associate it with
binary or jpeg type data.

Scripts are now considered by many to be obsolete, you may want to stick
with syntax and use Python to generlize.

If this does not meet your needs please repost and ask specifically
about using python.

Art Kendall
Social Research Consultants



On 6/28/2010 10:31 AM, Malanding Jaiteh wrote:

I am trying to import several 1000  ascii (*.TXT ) raster files into
into single variable SPSS files (syntax below for 1 file). I am new to
SPSS scripting so I am looking for samples (basic or vb) that I can
learn from?

Thanks,
Malanding Jaiteh


GET DATA
 /TYPE=TXT
 /FILE='G:\*2.txt'
 /DELCASE=VARIABLES 1
 /DELIMITERS="\t "
 /ARRANGEMENT=DELIMITED
 /FIRSTCASE=1
 /IMPORTCASE=ALL
 /VARIABLES=
 Variable1 F13.3.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.
SAVE OUTFILE='G:\*2.sav'
 /COMPRESSED.

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


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

 

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