Exporting Data to text files with additional comments

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

Exporting Data to text files with additional comments

Mario Giesel
Hello, SPSS friends,

  I'm trying to export *.sav data into tab separated text files.
I did not find a solution via SAVE TRANSLATE or WRITE.
The export includes values of one variable.
Above the values I want to insert comments like in the example below:

[Target Info]
Text1="Male"
Text2="18-65 years"
0
1
0
0
1
0
0
1
0
0
0
1

Any ideas how I can automate this via syntax?
Thanks for any suggestion.
  Mario
Mario Giesel
Munich, Germany
Reply | Threaded
Open this post in threaded view
|

Re: Exporting Data to text files with additional comments

Andy W
For such a simple example, PRINT would work fine. For more complicated examples (e.g. you want to the file to be csv delimited with quotations for strings etc.) you may need to physically add the header cases into the file (which would require converting the integers to strings) and then export the file using the usual means.

************************************.
DATA LIST FREE / X.
BEGIN DATA
0
1
0
0
1
0
0
1
0
0
0
1
END DATA.
FORMATS X (F1.0).
FILE HANDLE test /NAME = "C:\Users\andrew.wheeler\Documents\SPSSDocs".

DO IF $casenum = 1.
PRINT OUTFILE = "test\Test.txt"
      /'[Target Info]'
      /'Text1="Male"'
      /'Text2="18-65 years"'.
END IF.
PRINT OUTFILE = "test\Test.txt"
      /X.
EXECUTE.
************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Exporting Data to text files with additional comments

David Marso
Administrator
FWIW, to generate a tab, create a variable with the value 8 and format it as PIB.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Exporting Data to text files with additional comments

Ruben Geert van den Berg
In reply to this post by Mario Giesel
Dear Mario,

Where do the comment texts come from? Is there any clear structure in them that's related to the data? Is it (theoretically) possible to generate them automatically? How many .txt files do you want to write?

If it concerns many .txt files and there's a fixed structure in the comment texts you could perhaps use Python to generate the text files for you. I did something (reasonably) similar here: http://spss-tutorials.com/downloads/LI-orthoplan_00.sps.

Best,

Ruben