SPSS Statistics

 View Only
Expand all | Collapse all

Split file to csv

  • 1.  Split file to csv

    Posted Sat August 08, 2020 10:44 AM

    Is there a way to use the python plugin below but save the outfile as a csv or excel file?

    Is there a way to use the python plugin below, but save the out file as a csv or excel file? Here is an example of the syntax for an SPSSINC SPLIT DATASET command. Suppose for this example that the split file variable is called COUNTY. spssinc split dataset splitvar = county /OUTPUT DIRECTORY= "C:\county_files" DELETECONTENTS = NO FILENAME = "County_${county}_accounts" /OPTIONS NAMES =VALUES PRINTLIST=YES .






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: Split file to csv
    Best Answer

    Posted Sat August 08, 2020 01:31 PM

    Sorry. SPLIT DATASET only makes sav files. However, you can use the companion extension command SPSSINC PROCESS FILES to open each of those and save them as csv files. SPLIT DATASET can construct a list of files produced, and you can feed that to PROCESS FILES to run a syntax file against each one.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: Split file to csv
    Best Answer

    Posted Thu August 13, 2020 02:03 PM

    Can you post an example of what that would look like? Thanks.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 4.  RE: Split file to csv
    Best Answer

    Posted Thu August 13, 2020 05:12 PM

    Here is what to do.

    Create a syntax file, say ConvertSavToCsv.sps with these contents. You have to remove all the blank lines below due to quirks with this site.

    This file opens each file that PROCESS FILES provides to it and saves it as a csv file with the same name but extension csv in the same directory as the input.

    define !out () !quote(!concat(!unquote(!eval(!JOB_DATADIR)),

      !unquote(!eval(!JOB_DATAFILEROOT)), "csv")) !enddefine.

    GET FILE=JOB_INPUTFILE.

    SAVE TRANSLATE OUTFILE=!out

     /TYPE=CSV

     /ENCODING='UTF8'

     /MAP

     /REPLACE

     /FIELDNAMES

     /CELLS=VALUES.

    ----------------------

    Then run a command like this. (Again, remove blank lines.) In this example, it reads all files like emp*.sav in the temp directory and applies the syntax file also located in c:\temp.

    If you have a file list from running SPLIT DATASET, change the INPUTDATA spec to

    FILELIST = "filespec"

    where filespec is the full path for that file.

    SPSSINC PROCESS FILES INPUTDATA="c:\temp\emp*.sav"  

    SYNTAX="c:\temp\convertSavToCsv.sps" CONTINUEONERROR=YES

    VIEWERFILE= "c:\temp\convert.spv" CLOSEDATA=YES.







    #SPSSStatistics
    #Support
    #SupportMigration


  • 5.  RE: Split file to csv
    Best Answer

    Posted Fri August 14, 2020 07:07 PM

    Thank you, this is really helpful.






    #SPSSStatistics
    #Support
    #SupportMigration