import multiples files txt

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

import multiples files txt

Javier Meneses
Hi, please help me.

I have a directory with multiple text files and want to import it into SPSS with a fixed structure and save it with the same name that originally brought. As I can do this?

My files ares sorted so:

Exp_AR_2006
Imp_AR_2006
....
....
..
Exp_BR_2011
Imp_BR_2011

My sintax for one file is:


GET DATA  /TYPE=TXT
  /FILE="C:\....\EXP_AR_2006.TXT"
  /ENCODING='Locale'
  /FIXCASE=1
  /ARRANGEMENT=FIXED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  /1 periodo 0-0 F1.0
  año 1-4 F4.0
  informante 5-7 F3.0
  comercio 8-8 F1.0
  prorigen 9-11 A3
  p_proc 12-14 A3
  arancel 15-24 A10
  partida 25-28 A4
  subparitda 29-30 A2
  kilo_B 31-43 F13.0
  Kilo_N 44-56 F13.0
  code_Uni 57-58 F2.0
  cantidad 59-71 F13.0
  cif_fob 72-84 F13.0
  fob 85-97 F13.0
  seguro 98-110 F13.0
  flete 111-123 F13.0
  medio_t 124-124 F1.0
  bandera 126-128 F3.0.
  puerto   129-132 F3.0.
CACHE.
EXECUTE.


SAVE OUTFILE='C:\....\Exp_Ar_2006.sav'
  /COMPRESSED.

  Thank...Javier
===================== 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: import multiples files txt

Jon K Peck
The easiest way to automate doing this would be to use the SPSSINC PROCESS FILES extension command, which requires the Python Essentials.

You create a syntax file containing your GET command but referring to the input with a file handle provided by PROCESS FILES.  You also use a macro provided by PROCESS FILES to construct the output file name from the input and use it in a SAVE command.  Then the inputs to PROCESS FILES include the name of your syntax file and a specification of the files to read (usually a wildcard such as c:\somedirectory\*.txt), and it will iterate the syntax over all matching files.

With Statistics 22, if you have already installed the Python Essentials, you can install PROCESS FILES from the Utilities menu.  For older version you would get the command from the Extension bundles collection via the SPSS Community website (www.ibm.com/developerworks/spssdevcentral)


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        javier meneses <[hidden email]>
To:        [hidden email]
Date:        09/04/2014 01:45 PM
Subject:        [SPSSX-L] import multiples files txt
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi, please help me.

I have a directory with multiple text files and want to import it into SPSS with a fixed structure and save it with the same name that originally brought. As I can do this?

My files ares sorted so:

Exp_AR_2006
Imp_AR_2006
....
....
..
Exp_BR_2011
Imp_BR_2011

My sintax for one file is:


GET DATA  /TYPE=TXT
  /FILE="C:\....\EXP_AR_2006.TXT"
  /ENCODING='Locale'
  /FIXCASE=1
  /ARRANGEMENT=FIXED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  /1 periodo 0-0 F1.0
  año 1-4 F4.0
  informante 5-7 F3.0
  comercio 8-8 F1.0
  prorigen 9-11 A3
  p_proc 12-14 A3
  arancel 15-24 A10
  partida 25-28 A4
  subparitda 29-30 A2
  kilo_B 31-43 F13.0
  Kilo_N 44-56 F13.0
  code_Uni 57-58 F2.0
  cantidad 59-71 F13.0
  cif_fob 72-84 F13.0
  fob 85-97 F13.0
  seguro 98-110 F13.0
  flete 111-123 F13.0
  medio_t 124-124 F1.0
  bandera 126-128 F3.0.
  puerto   129-132 F3.0.
CACHE.
EXECUTE.


SAVE OUTFILE='C:\....\Exp_Ar_2006.sav'
  /COMPRESSED.

  Thank...Javier
===================== 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 [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
|

import multiples files txt

Javier Meneses
In reply to this post by Javier Meneses
I am not sure if this message was sended it.

Hi, please help me.

I have a directory with multiple text files and want to import it into SPSS with a fixed structure and save it with the same name that originally brought. As I can do this?

My files ares sorted so:

Exp_AR_2006
Imp_AR_2006
....
....
..
Exp_BR_2011
Imp_BR_2011

My sintax for one file is:


GET DATA  /TYPE=TXT
  /FILE="C:\....\EXP_AR_2006.TXT"
  /ENCODING='Locale'
  /FIXCASE=1
  /ARRANGEMENT=FIXED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  /1 periodo 0-0 F1.0
  año 1-4 F4.0
  informante 5-7 F3.0
  comercio 8-8 F1.0
  prorigen 9-11 A3
  p_proc 12-14 A3
  arancel 15-24 A10
  partida 25-28 A4
  subparitda 29-30 A2
  kilo_B 31-43 F13.0
  Kilo_N 44-56 F13.0
  code_Uni 57-58 F2.0
  cantidad 59-71 F13.0
  cif_fob 72-84 F13.0
  fob 85-97 F13.0
  seguro 98-110 F13.0
  flete 111-123 F13.0
  medio_t 124-124 F1.0
  bandera 126-128 F3.0.
  puerto   129-132 F3.0.
CACHE.
EXECUTE.


SAVE OUTFILE='C:\....\Exp_Ar_2006.sav'
  /COMPRESSED.

  Thank...Javier 
===================== 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: import multiples files txt

Bruce Weaver
Administrator
It was sent, and Jon Peck responded.  

http://spssx-discussion.1045642.n5.nabble.com/import-multiples-files-txt-tp5727159p5727161.html


Javier Meneses wrote
I am not sure if this message was sended it.

Hi, please help me.

I have a directory with multiple text files and want to import it into SPSS
with a fixed structure and save it with the same name that originally
brought. As I can do this?

My files ares sorted so:

Exp_AR_2006
Imp_AR_2006
....
....
..
Exp_BR_2011
Imp_BR_2011

My sintax for one file is:


GET DATA  /TYPE=TXT
  /FILE="C:\....\EXP_AR_2006.TXT"
  /ENCODING='Locale'
  /FIXCASE=1
  /ARRANGEMENT=FIXED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  /1 periodo 0-0 F1.0
  año 1-4 F4.0
  informante 5-7 F3.0
  comercio 8-8 F1.0
  prorigen 9-11 A3
  p_proc 12-14 A3
  arancel 15-24 A10
  partida 25-28 A4
  subparitda 29-30 A2
  kilo_B 31-43 F13.0
  Kilo_N 44-56 F13.0
  code_Uni 57-58 F2.0
  cantidad 59-71 F13.0
  cif_fob 72-84 F13.0
  fob 85-97 F13.0
  seguro 98-110 F13.0
  flete 111-123 F13.0
  medio_t 124-124 F1.0
  bandera 126-128 F3.0.
  puerto   129-132 F3.0.
CACHE.
EXECUTE.


SAVE OUTFILE='C:\....\Exp_Ar_2006.sav'
  /COMPRESSED.

  Thank...Javier

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: import multiples files txt

Mario Giesel
* Something like this would probably work (untested).

FILE HANDLE path /NAME = "C:\\mypath" /* please edit */.

/* ===================================== BEGIN of MACRO */
DEFINE @txt2spss  (!POS !CMDEND)
PRESERVE.
SET MPRINT = ON PRINTBACK = ON.
!DO !i !IN (!1)
   !LET !infile = !CONCAT(!UNQUOTE(!i),'.txt')
   !LET !oufile = !CONCAT(!UNQUOTE(!i),'.sav')

GET DATA  /TYPE=TXT
  /FILE= !QUOTE(!infile)
  /ENCODING='Locale'
  /FIXCASE=1
  /ARRANGEMENT=FIXED
  /FIRSTCASE=1
  /IMPORTCASE=ALL
  /VARIABLES=
  /1 periodo 0-0 F1.0
  año 1-4 F4.0
  informante 5-7 F3.0
  comercio 8-8 F1.0
  prorigen 9-11 A3
  p_proc 12-14 A3
  arancel 15-24 A10
  partida 25-28 A4
  subparitda 29-30 A2
  kilo_B 31-43 F13.0
  Kilo_N 44-56 F13.0
  code_Uni 57-58 F2.0
  cantidad 59-71 F13.0
  cif_fob 72-84 F13.0
  fob 85-97 F13.0
  seguro 98-110 F13.0
  flete 111-123 F13.0
  medio_t 124-124 F1.0
  bandera 126-128 F3.0.
  puerto   129-132 F3.0.
CACHE.
EXECUTE.
SAVE OUTFILE= !QUOTE(!oufile)
  /COMPRESSED.
RESTORE.
!ENDDEFINE.
/* ===================================== END of MACRO */

@txt2spss
'path\EXP_AR_2006'
'path\Imp_AR_2006'
....
....
'path\Exp_BR_2011'
'path\Imp_BR_2011'
.

GL,
  Mario


Bruce Weaver <[hidden email]> schrieb am 23:47 Montag, 8.September 2014:


It was sent, and Jon Peck responded. 

http://spssx-discussion.1045642.n5.nabble.com/import-multiples-files-txt-tp5727159p5727161.html



Javier Meneses wrote

> I am not sure if this message was sended it.
>
> Hi, please help me.
>
> I have a directory with multiple text files and want to import it into
> SPSS
> with a fixed structure and save it with the same name that originally
> brought. As I can do this?
>
> My files ares sorted so:
>
> Exp_AR_2006
> Imp_AR_2006
> ....
> ....
> ..
> Exp_BR_2011
> Imp_BR_2011
>
> My sintax for one file is:
>
>
> GET DATA  /TYPE=TXT
>  /FILE="C:\....\EXP_AR_2006.TXT"
>  /ENCODING='Locale'
>  /FIXCASE=1
>  /ARRANGEMENT=FIXED
>  /FIRSTCASE=1
>  /IMPORTCASE=ALL
>  /VARIABLES=
>  /1 periodo 0-0 F1.0
>  año 1-4 F4.0
>  informante 5-7 F3.0
>  comercio 8-8 F1.0
>  prorigen 9-11 A3
>  p_proc 12-14 A3
>  arancel 15-24 A10
>  partida 25-28 A4
>  subparitda 29-30 A2
>  kilo_B 31-43 F13.0
>  Kilo_N 44-56 F13.0
>  code_Uni 57-58 F2.0
>  cantidad 59-71 F13.0
>  cif_fob 72-84 F13.0
>  fob 85-97 F13.0
>  seguro 98-110 F13.0
>  flete 111-123 F13.0
>  medio_t 124-124 F1.0
>  bandera 126-128 F3.0.
>  puerto  129-132 F3.0.
> CACHE.
> EXECUTE.
>
>
> SAVE OUTFILE='C:\....\Exp_Ar_2006.sav'
>  /COMPRESSED.
>
>  Thank...Javier
>
> =====================
> 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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/import-multiples-files-txt-tp5727159p5727183.html
Sent from the SPSSX Discussion mailing list archive at 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


===================== 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
Mario Giesel
Munich, Germany