SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files

    Posted Wed June 02, 2021 03:16 AM
    Hello fellow data scientists

    I seek help with the SPSSINC PROCESS FILES- I have a massive amount of SAV files that I need to convert to XLSX files.

    I am following the example provided in the SPSS-X discussion (split file. Export to Excel with split variables as filename.
    Nabble remove preview
    split file. Export to Excel with split variables as filename.
    split file. Export to Excel with split variables as filename. I have been looking at SPSSX-l on my phone but have a hard time reading the results. I have the impression there are SPSSINC ways to do...
    View this on Nabble >
    ):

    * save subsets of cases to SAV files.
    SPSSINC SPLIT DATASET SPLITVAR=city_code
    /OUTPUT DIRECTORY= "C:\temp\final\original" DELETECONTENTS=NO
    /OPTIONS NAMES=values PRINTLIST=YES
    FILELIST="C:\temp\final\original\list new".

    * Bring back in each SAV with a subset of cases then save it as an Excel XLSX spreadsheet.

    define !input () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)), !unquote(!eval(!JOB_DATAFILEROOT)), ".sav")) !enddefine.
    Xdefine !out () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)), !unquote(!eval(!JOB_DATAFILEROOT)), ".xlsx")) !enddefine.

    SPSSINC PROCESS FILES
    SYNTAX ="C:\temp\final\SPSS sav to xlsx.sps"
    INPUTDATA="C:\temp\final\original"
    OUTPUTDATADIR="C:\temp\final"
    LOGFILE="C:\temp\final\original\LOG PROCESS FILES.TXT"
    CLOSEDATA=YES.

    the SPS file inserted is:

    GET
    FILE=!input.

    SAVE TRANSLATE OUTFILE=!out
    /TYPE=XLS
    /VERSION=12
    /MAP
    /FIELDNAMES VALUE=NAMES
    /CELLS=VALUES
    /REPLACE.

    *****************

    This example does not function and can not process the SAV files to XLSX files.

    Does someone know how to take such an issue? maybe the define !input or !out are wrong?
    thanks!


    ------------------------------
    Meni Berger
    ------------------------------

    #SPSSStatistics


  • 2.  RE: SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files

    Posted Wed June 02, 2021 08:54 AM
    Edited by System Admin Fri January 20, 2023 04:27 PM
    Hi. It looks like there's a typo in what you have re-printed from that X-list conversation. You have

    define !input () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)), !unquote(!eval(!JOB_DATAFILEROOT)), ".sav")) !enddefine.
    Xdefine !out () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)), !unquote(!eval(!JOB_DATAFILEROOT)), ".xlsx")) !enddefine.

    Since these are both MACRO definitions they must begin with DEFINE. The 2nd one you have there says "Xdefine," which will produce an error, and !OUT won't be recognized. Remove the X, make sure you are running two DEFINE commands, run the whole thing again, and see if that makes any difference.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files

    Posted Thu June 03, 2021 08:09 AM
    Thank you, dear Rick

    The naughty 'X' isn't in the original syntax. must have gotten there by mistake.

    also the capitalization of the DEFINE !ENDDEFINE command had no effect on the working of the syntax.

    although the suggestion Jon made work just fine.

    ------------------------------
    Meni Berger
    ------------------------------



  • 4.  RE: SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files
    Best Answer

    Posted Wed June 02, 2021 09:02 AM
    Here is an example from the PROCESS FILES syntax help.  It does the opposite - converting Excel files to sav files, but you can flip this around to do the opposite.  Instead of GET DATA, you would use GET with JOB_INPUTFILE as the file, and instead of SAVE, it would be SAVE TRANSLATE.  The macro would have "*.xlsx" instead of ".sav".

    define !out () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)), !unquote(!eval(!JOB_DATAFILEROOT)), ".sav")) !enddefine. GET DATA /TYPE=XLSX /FILE=JOB_INPUTFILE /SHEET=name 'Sheet1' /CELLRANGE=full /READNAMES=on /ASSUMEDSTRWIDTH=100. SAVE OUTFILE=!out.

    --





  • 5.  RE: SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files

    Posted Thu June 03, 2021 08:18 AM
    Hello Dear @Jon Peck,

    Yet again you saved the day! many thanks to you!

    this worked for me as you suggested.

    Also- I have noticed the SPSSINC PROCESS FILES names the XLSX files sequentially.

    Is it capable of naming the by the original SAV file name?

    *****************
    code example:
    *****************

    SPSSINC SPLIT DATASET SPLITVAR=city_code
    /OUTPUT DIRECTORY= "C:\temp\final\small" DELETECONTENTS=NO
    /OPTIONS NAMES=values PRINTLIST=YES
    FILELIST="C:\temp\list new".

    DEFINE !out () !quote(!concat(!unquote(!eval(!JOB_OUTPUTDATADIR)),
    !unquote(!eval(!JOB_DATAFILEROOT)), ".xlsx")) !ENDDEFINE.

    SPSSINC PROCESS FILES
    SYNTAX ="C:\temp\final\SPSS sav to xlsx.sps"
    INPUTDATA="C:\temp\final\small"
    OUTPUTDATADIR="C:\temp\final\small"
    LOGFILE="C:\temp\LOG PROCESS FILES.TXT"
    CLOSEDATA=YES.

    and the "SPSS sav to xlsx.sps" file has in it:

    GET
    FILE="JOB_INPUTFILE".

    SAVE TRANSLATE OUTFILE=!out
    /TYPE=XLS
    /VERSION=12
    /MAP
    /FIELDNAMES VALUE=NAMES
    /CELLS=VALUES
    /REPLACE.




    ------------------------------
    Meni Berger
    ------------------------------



  • 6.  RE: SPSSINC PROCESS FILES fails when trying to mass convert SAV files to XLSX files

    Posted Thu June 03, 2021 08:57 AM
    The !JOB_DATAFILEROOT evaluates to the name of the input data file without its extension and excluding the path information, so the !out macro should produce an output name matching the input.

    Try running SET MPRINT ON. before process files to see the expanded !out definition.  (Try this with a small number of input files!)

    --