SPSS Statistics

SPSS Statistics

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

 View Only
Expand all | Collapse all

SPSS Data Editor, save data as SQL insert script

  • 1.  SPSS Data Editor, save data as SQL insert script

    Posted Wed September 02, 2020 12:20 PM

    At work we're using SPSS Statistics v23, and I was wondering if it's possible to save a SPSS dataset as SQL insert script. So I mean in the same way a backup file from MySQL contains insert statements, in subselects of (iirc) 1000 or so records.

    From the Data Editor there are options to save as CSV, Excel, SAS, STATA etc. and I've created my own scripts to "reformat" a CSV export file into such a SQL script. I understand it's perhaps a bit unusual file format, but for quickly importing some smaller ad-hoc data files I find it's very useful imho.

    cheers,

    Bas






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: SPSS Data Editor, save data as SQL insert script

    Posted Wed September 02, 2020 01:08 PM

    You can use the Database Wizard to construct database export syntax. Here is an example exporting the active file to MySQL. It uses the SAVE TRANSLATE command with a SQL subcommand.

    SAVE TRANSLATE /TYPE=ODBC

    /BULKLOADING BATCHSIZE=10000 METHOD=BATCH

    /CONNECT='DSN=mySQL;'

    /ENCRYPTED

    /MISSING=IGNORE

    /SQL='CREATE TABLE exported (bdate date , educ double , gender varchar (6), id double , jobcat '+

    'double , jobtime double , minority double , prevexp double , salary double , salbegin double '+

    ', strWNBSP varchar (8))'

    /REPLACE

    /TABLE='SPSS_TEMP'

    /KEEP=bdate, educ, gender, id, jobcat, jobtime, minority, prevexp, salary, salbegin, strWNBSP

    /SQL='INSERT INTO exported (bdate, educ, gender, id, jobcat, jobtime, minority, prevexp, '+

    'salary, salbegin, strWNBSP) SELECT bdate, educ, gender, id, jobcat, jobtime, minority, '+

    'prevexp, salary, salbegin, strWNBSP FROM SPSS_TEMP'

    /SQL='DROP TABLE SPSS_TEMP'.






    #SPSSStatistics
    #Support
    #SupportMigration