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

Start up Script and Exporting Each custom table as a separate tab in excel

  • 1.  Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Mon September 16, 2024 10:03 AM

    Hi -

    New here. Hoping you can help! I have 2 issues I am trying to solve. 

    1) I have created a number of macros that I would like to run at Startup. Previously you could put the macro file in the root folder and SPSS would run it every time it opened. But with the new version I cannot figure out how to auto run a start up spss syntax file I have a workaround using insert file but I would prefer to have it run at startup. Any ideas? 

    2) When exporting a range of tables I would like to have SPSS export each table into separate excel tabs. I recall a much older version of SPSS used to allow for that. The latest version does not. Anyone know of a way to make that happen. 

    thanks in adavance!

    Best,

    Ratna



    ------------------------------
    Ratna Wynn
    ------------------------------


  • 2.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Mon September 16, 2024 10:10 PM
    On the first point, I suggest that you install the STATS OPEN PROJECT extension command from Extensions > Extension Hub.  It provides facilities for defining and activating projects, and it has an open to automatically run commands, macro definitions, etc when you start SPSS.  You can create a script to be run at startup, but OPEN PROJECT is a lot more powerful and easy to use,   It does requires a little more setup, but you don't need to write a script.

    On the second point, install the STATS MODIFY OUTPUT extension command.  It comes with a number of utility scripts that can be run by the command.  They are in a file named customoutputfunctions.py.  If you open that file in a plain text editor, you will see a function called excelexport.  There are examples there of how to use this function.  The advantage over the simple File > Export menu item or equivalent syntax is that you can select the tables to export based on their OMS type.  It gives you several choices for the target Excel file, including each table in a separate tab of a single file.

    The customoutputfunctions.py file will be in the standard location for extensions.  If you don't know where that is, run the SHOW EXT command to see the possible installation locations.

    --





  • 3.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 22, 2024 04:34 PM
    Edited by Ratna Wynn Sun September 22, 2024 04:49 PM

    Thank you, Jon! 

    On the start up script - I have installed Stats Open Project and after reading the README file I ran this command: 

    Stats Open project file = "C:\Users\ratna.wynn\OneDrive -OneWorkplace\desktop\SPSS LOG\Marco.sps" STARTUP = SET. 

    I get this error. 

    Can you tell me what I am doing incorrectly? Also do I have to run this every time or just once?

    On the second one. I did install the extension bundle Modify table output. I ran the following code. 

    SPSSINC MODIFY OUTPUT TABLES 
    /IF SUBTYPE="'Custom Table'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport(file='C:\Users\ratna.wynn\OneDrive - OneWorkplace\DESKTOP\SPSS LOG\output.xls'',  sheet='table#',action='CreateWorksheet')".

    But get this error:

    Can you please let me know what I am doing wrong here too. I wonder if it has to do with Python and something not working there. Thanks! 



    ------------------------------
    Ratna Wynn
    ------------------------------



  • 4.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 22, 2024 05:13 PM
    It is trying to write a script file to the directory where SPSS looks for a startup script.  However, it appears that that directory is not created by the SPSS installation in the latest version, and that location is not writeable.

    I need to find out where SPSS now looks for startup scripts.



    --





  • 5.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 22, 2024 05:34 PM

    In the meantime,  you can use this facility but not set the project as a startup script.  You would use File > Open > Project and select the appropriate project file.  Of course, this only helps if you need more than one file opened in terms of the manual steps.  I will update the OPEN PROJECT extension once we figure this out.



    ------------------------------
    Jon Peck
    Data Scientist
    JKP Associates
    Santa Fe
    ------------------------------



  • 6.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 22, 2024 06:45 PM

    Ok - I will wait to hear more. We are now using the import file command but this needs to be run every time at the start of syntax script. In an older version of SPSS I was able to save the macro file in the SPSS base directory and it would run at start up automatically. That does not seems to work anymore. Thank you for looking into this. 



    ------------------------------
    Ratna Wynn
    ------------------------------



  • 7.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Mon September 23, 2024 04:11 PM
    I have updated the STATS OPEN PROJECT extension command to accommodate some changes that occurred, probably, in Statistics 29.  If it is unable to install a startup script, it will print instructions on what to do to resolve the issue.

    The new version will go on the Extension Hub, but first, I would like to see it tested by a user.  The new version is 2.0.5.

    Download it from
    and install it via Extensions > Install local extension bundle.  Then, if it has been used in the current session, restart Statistics.



    --





  • 8.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Mon September 23, 2024 10:24 PM

    Hi Jon - thank you. I was able to install and run it and got the following error message. I can have IT tomorrow install the folder but the path is cut off. Can you tell me what the folder ultimately needs to be called? Or do I need to open the computer in admin mode and then run the command?



    ------------------------------
    Ratna Wynn
    ------------------------------



  • 9.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Mon September 23, 2024 10:59 PM
    I don't see anything cut off in the message, although it is using the old compressed names format.  It refers to the scripts subdirectory under your Statistics installation.  I don't know why that form comes up sometimes.  It would probably work, but I don't have a way to test that, because it doesn't use that format on my system.

    I changed the code to use a different api to get the SPSS installation location.  You can get that version of the spe file here and install it as before.

    In a fresh SPSS session that has not run this command, try the revised version.








  • 10.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Fri September 27, 2024 10:08 AM

    Thanks! Will try and let  you know.



    ------------------------------
    Ratna Wynn
    ------------------------------



  • 11.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sat September 28, 2024 03:37 PM

    Thanks, Jon. I installed the new extension and still get this error. Anything else I can try?



    ------------------------------
    Ratna Wynn
    ------------------------------



  • 12.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sat September 28, 2024 05:23 PM
    Windows has a setting about 8.3 names.  If you run this in a Command window,
    fsutil 8dot3name
    it will show the setting on your system.
    See this page.
    On my system, it returns 2, which means to allow these
    fsutil 8dot3name set
    can be used to change this setting
     
    The other possibility, which is more likely, is just that you need admin permission to create this directory.

    Once that directory is created and a script is installed to run a file,  you can just change the contents of that file, which would be stored somewhere writable, to change the preferences.






  • 13.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 29, 2024 09:10 PM

    Of course, if all else fails, you might be able to go to the SPSS installation directory and create an empty subdirectory named scripts.  Then the command might work.



    ------------------------------
    Jon Peck
    Data Scientist
    JKP Associates
    Santa Fe
    ------------------------------



  • 14.  RE: Start up Script and Exporting Each custom table as a separate tab in excel

    Posted Sun September 22, 2024 06:43 PM

    Ok thank you



    ------------------------------
    Ratna Wynn
    ------------------------------