SPSS Statistics

 View Only
Expand all | Collapse all

Controlling What gets Exported to Excel

  • 1.  Controlling What gets Exported to Excel

    Posted 14 days ago
    Edited by Mark Sloan 14 days ago

    I have successfully developed a consolidated MIXED syntax that processes a series of models, creates graphs/plots to assess assumptions, and presents model output before and after removal of extreme outliers.  My next need is to export model-only output to EXCEL (3 before and 3 after MIXED models) with no extraneous tables or graphs.  To this end I am trying to use the WORKBOOK EXPORT function to control what gets exported to Excel:

    * Export Workbook.
    WORKBOOK EXPORT
      /CONTENTS  EXPORT=VISIBLE  LAYERS=VISIBLE  MODELVIEWS=VISIBLE
      /XLSM  DOCUMENTFILE='D:\SPSS-RESULTS\test-output-delete-later.xlsm'
         OPERATION=CREATESHEET
         LOCATION=LASTCOLUMN  NOTESCAPTIONS=YES.

    Here is what I want to suppress: entire syntax up front (hide this), Notes, Model Descriptions, Graphs/Plots.  The above syntax successfully suppresses Notes and Model Descriptions, but not syntax (too long) and the graphs/plots.  Are their additional subcommands that do this, or is OMS the only way? 'Utilities > OMS Control Panel' appears to only produce XML output, and I need .xlsm-based output.  

    An alternative is to manually-select each of the tables from each model: right-click "Export..." and select "Objects to Export > Selected" with Type > Excel...., and filename.  This roughly does what I am trying to do, but I need to automate this in syntax.

    Thanks!

    ------------------------------
    Mark Sloan
    ------------------------------



  • 2.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    I never use WORKBOOK model, but WORKBOOK EXPORT appears to support the VISIBLE mode for selecting the output to export.  So if you go to Edit > Options and mark the output types  you want to have not visible by default, that would suppress the things you don't want, I suppose.

    If that doesn't work, just using the regular mode would give you control over the items exported, including based on visibility.  If you use the SPSSINC MODIFY OUTPUT extension command in that mode, you can select the table types  you want exported based on their OMS types using the customoutput.excelexport. function installed with that command.

    --





  • 3.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago
    Edited by Mark Sloan 14 days ago

    I have been working exclusively in Workbook mode since I discovered it, and it works really well for testing and retesting new sections of syntax without overclogging the viewer.  That said, I can't seem to get the Edit > Options > Viewer tab to do anything apparent.  And I'm not sure how to get to regular mode or perform SPSSINC MODIFY OUTPUT.  I only used OMS for a couple of the mixed models (of 6) to create their random effects data, so not sure if I'm in the cold on the other 4 models.

    What I want is to be able to see what I currently see in the Workbook viewer as is (all titles, models, charts, tables), BUT only export to Excel just the TITLE, Mixed Model Analysis, Fixed Effects, and Covariance Parameter tables for each of 6 models and that's it.

    What would be the best resource for learning this?  The videos I see don't seem to get to the automation level.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 4.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    Workbook mode is kind of separate from the regular Viewer and lacks a lot of functionality.  Its doc says that OMS is not available in that mode, but I expect that syntax you generate that way would work in regular mode except for WORKBOOK commands, which would need to be replaced by OUTPUT EXPORT, OUTPUT SAVE and similar.

    SPSSINC MODIFY OUTPUT is an extension command that you would install via Extensions > Extension Hub.  It will appear on the Update menu, but, of course, it would not work in workbook mode.

    In regular mode, you could set the visibility of each type of Viewer output, which might be sufficient.  Otherwise, SPSSINC MODIFY OUTPUT with the function I mentioned would let you pick up items of a particular OMS type for export.  You can find the OMS type for any table via Utilities > OMS Identifiers or by right clicking on its outline entry and choosing Copy OMS type.

    --





  • 5.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago
    Edited by Mark Sloan 14 days ago

    Thank you.  I'll give it a shot tonight.  I just figured out how to find the OMS Command Identifier, OMS Subtype, and OMS Label for each item, which is very helpful. 

    How should I get to regular mode from Workbook mode? Do I have to make changes in Edit > Options to "Classic"?  I normally work and test code in workbook mode because it "writes over" the mistakes so I don't get overwhelmed with the output.  My novice-ness is quickly coming out!

    I just installed 7 extensions hoping to get the right one for SPSSINC MODIFY OUTPUT.

    ------------------------------
    Mark Sloan
    ------------------------------



  • 6.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    Yes, you switch modes via Edit > Options

    --





  • 7.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago

    It appears SPSSINC MODIFY INPUT is a Python code?  Would you have/know of any sample routines that might allow control over items to export to Excel?  The last sample routines were extremely helpful and I could not have proceeded without them. Thank you!



    ------------------------------
    Mark Sloan
    ------------------------------



  • 8.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago

    I tried MENU Utilities > Modify Output Titles, and got to this:

    SPSSINC MODIFY OUTPUT MODELS TITLES 
    /IF COMMAND="Mixed" 
    ITEMTITLE= "execute" PROCESS=PRECEDING
    /REPLACE ITEMS.

    and then tried again:

    * Export Workbook.
    WORKBOOK EXPORT
      /CONTENTS  EXPORT=VISIBLE  LAYERS=VISIBLE MODELVIEWS=VISIBLE
      /XLSM  DOCUMENTFILE=' D:\SPSS-RESULTS-REPOSITORY\test-output-delete-later.xlsm '
         OPERATION=CREATEFILE
         LOCATION=LASTCOLUMN  NOTESCAPTIONS=YES.
    But this still produces almost everything from my workbook except for notes and model descriptions.  Would like to produce only models and their tables with the OMS Command Identifier "Mixed" and all titles that contain the word "execute" (among more text).  If this occurs I think I will be good to go.
    Thanks for your patience!


    ------------------------------
    Mark Sloan
    ------------------------------



  • 9.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    You have to be in regular output mode with regular Viewer output to use this.--





  • 10.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago

    Copy and switched over.  I'll go through this in more detail tonight, but things are now tracking....



    ------------------------------
    Mark Sloan
    ------------------------------



  • 11.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    Extension commands such as MODIFY OUTPUT are written in Python or R, but the user only sees their syntax, which looks just like regular built-in SPSS commands.  No Python or R knowledge is required to use them except for some that allow custom Python functions to be plugged in.

    Here is an example.
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Descriptive Statistics'"
    PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport(file='c:/temp/mytable.xlsx')".

    Other parameters for the function and examples can be found in the customoutputfunctions.py module installed with this extension command.

    --





  • 12.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago

    Excellent, I'll try it tonight!



    ------------------------------
    Mark Sloan
    ------------------------------



  • 13.  RE: Controlling What gets Exported to Excel

    Posted 14 days ago
    Edited by Mark Sloan 14 days ago

    I was unfortunately unable to get anything to work tonight.  First, I used the Extensions > Extension Hub... to download all extensions related to the word search:  "SPSSINC".  I have many extensions now loaded to get the right one, but not sure which actually contains "SPSSINC MODIFY INPUT" or "customoutputfunctions.excelexport".

    I also opened a new classic Syntax Editor, and ran this syntax:

    show all.

    I got the System Settings, License components, Versions, and System Variables, but unfortunately nothing that indicated if "SPSSINC MODIFY OUTPUT" or "customoutputfunctions.excelexport" were loaded.

    When I ran the example Python extension, it would not save into the various folders I tried to save to.  The Output editor did not indicate there were any errors.

    I think this is what I want, if I can just get it to work:

    SPSSINC MODIFY OUTPUT MODELS TITLES
    /IF SUBTYPE="'Mixed'"    <----or /IF COMMAND="'Mixed'"   ?
    PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport(file='d:/SPSS-RESULTS-REPOSITORY/mytable.xlsx')".

    and to add in a subcommand for TITLES that contain the word "EXECUTE".

    Should Mixed have both single and double quotes together?  Mixed is the OMS Command Identifier associated with all the tables of interest.  Any further ideas?  

    BTW, I am running SPSS 29.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 14.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 14 days ago
    It's SPSSINC MODIFY OUTPUT.  If you search for MODIFY OUTPUT on the Extension Hub, you will find it.  If you already got it installed, you won't see it on the EH list unless you check Installed at the bottom.  Check all three boxes.

    Once it is installed, it will appear as Utilities > Modify Output Titles.
    You would specify the OMS type for the table you want.  You don't need to also specify the command name in this case.

    SPSS allows literal strings to be either single or double quoted.  The CUSTOM subcommand used both types, because it needs quotes within quotes.  (There are other ways to do this, too.)

    You can use this to get multiple tables if needed, but let's start with the simple case of just looking at the preceding command output.

    SHOW ALL will  not display information about extensions.  If you need to manage them, you can install STATS EXTENSION REPORT, which will then show up on the Extensions menu.  It will give you a comprehensive list of installed extensions, and it can show what extensions are not installed or where an update is available.



    --





  • 15.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    MODIFY OUTPUT in the Extension Hub = good to go

    Utilities > Modify Output Titles = good to go

    Retried this syntax, adjusted for my computer and output:

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Descriptives'"
    PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport(file='d:/SPSS/mytable.xlsx')".

    It briefly worked, but now I cannot get it to work again.  I tried adding additional /IF statements to see if I could add TABLES to the successful Excel file, but now nothing works.  I am also now having trouble with "cut-and-paste" from forum text to SPSS Syntax Editor...I've seen this trouble with SPSS' cut-and-paste abilities before.  It feels like past bugs are coming back, and I am using a fresh install of SPSS on my machine.  Previously I was using a server at the university and saw similar behaviors.  Is there some kind of a reset without closing out SPSS that might clear up some of these things?

    Hit and miss success today.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 16.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    I rebooted and did some cleaning and it appears cut-and-paste is now working normally.  However, I retried MODIFY OUTPUT through both syntax and menu-paste, and neither work.  I cannot replicate the brief success of earlier today.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 17.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    After much testing, I am beginning to believe MODIFY OUTPUT only partially works, and it may be buggy.  I was able to consistently get "Descriptive Statistics" to save into an Excel file for a while, but now my working syntax no longer works.  I tried other object types/subtypes such as "Notes" (worked), and "Model Dimensions" from MIXED models (doesn't work).  After repeating syntax a few times, nothing works, not even the previously successful "Descriptive Statistics". 

    I tried creating the syntax from the menu version, and while had an initial success, it also failed to save after a few tries.

    I think this is the answer to what I need but I can't get it work consistently or properly.  I tried some of the other options, and was also unsuccessful.  If there are other options to send to Excel only certain tables and titles, it is greatly appreciated!

     



    ------------------------------
    Mark Sloan
    ------------------------------



  • 18.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 13 days ago
    I'm tied up today, but MODIFY OUTPUT has been around for  years and seems to be pretty reliable.  Remember that by default it looks only at the output from the immediately preceding procedure unless you specify ALL.

    I would need more information to figure this out.  If you want to send details, use my gmail address (jkpeck@gmail.com)

    --





  • 19.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    I think PRECEDING was the problem.  That said, I am trying to write multiple tables (Mixed model tables), but they are overwriting each other. I'm working to resolve, but if you catch this any help is appreciated.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 20.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 13 days ago
    From the function  help ...
    Example
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Custom Table'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport(file='c:/temp/extest.xls',
      sheet='table#',action='CreateWorksheet')".

        Use # in the file or sheet string to insert a sequential number on each
        save operation to avoid overwriting.

    --





  • 21.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    Thank you for the quick reply.  Floundering without this help.  I don't understand your last sentence.  What I want is to basically replicate most of the tables produced by the MIXED command (not all), and do this 6 times above each other on ONE Excel worksheet.  Basically this without writing over each other:

    MODEL 1

    'Model Dimension'

    'Information Criteria'

    'Intraclass Correlation Coefficients'

    'Parameter Estimates'

    'Covariance Parameter Estimates'

    MODEL 2

    (same as above)

    MODEL 3 etc.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 22.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    I tried what I think you meant....adding a number to the "#" in the syntax above, I just put "1", but it did not work. With what I am attempting to do, I really need to get everything (5 x 6 = 30 tables) onto a single Excel Tab (sheet) due to the sheer volume of models to process.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 23.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 13 days ago
    The full set of options for that function is this.  These work the same as the OUTPUT EXPORT options you see on the Export menu

    parameters:
        file - filespec for output (required)
        sheet - sheetname.  Default is "Sheet"
        action - "CreateWorkbook" | "Create Worksheet" | "ModifyWorksheet"
        location - "OverwriteAtCellRef" | "AddColumns" | "AddRows"
        startingCell - starting cell if location is overwrite.  Default is "A1"
        image - image format - "jpg" | "png" | "tiff" | "eps" | "emf" | "bmp"

    --





  • 24.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    I am so sorry, but this has me more confused.  Is there a good tutorial resource on how to build up an Excel sheet with multiple tables on it using SPSSINC MODIFY OUTPUT?  I've spend a lot of time on the web today trying to figure this out, and even reviewed a couple of help pdfs from SPSS, but nothing seems to address this adequately.



    ------------------------------
    Mark Sloan
    ------------------------------



  • 25.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    Reading through again, I think you mean the following, attempting to adapt to my situation:

    /CUSTOM FUNCTION="cutomoutputfunctions.excelexport (file='d:/spss/extest.xls, sheet='mixedmodels', action='ModifyWorksheet', location='OverwriteAtCellRef', startingCell='A50')"   <---no image format wanted

    Is this the right idea?  I just keep using the same filename to add on more and more tables?



    ------------------------------
    Mark Sloan
    ------------------------------



  • 26.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 13 days ago
    That's exactly backwards.  location='OverwriteAtCellRef', startingCell='A50' would overwrite every table if using the same file.  What I suggested was
    location = "AddRows" in the same file.
    That should append each table to the bottom of the same sheet.

    --





  • 27.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago

    Thank you!  I will try it out now.  I hope this brings this to a close.  Thank you for your patience with me on these issues!



    ------------------------------
    Mark Sloan
    ------------------------------



  • 28.  RE: Controlling What gets Exported to Excel

    Posted 13 days ago
      |   view attached

    I just tried to put 5 mixed tables on a sheet and 3 of them made it.  Two did not.  The startingCell control doesn't seem to work beyond the first table.  Also, the formatting of cells is a bit funky....earlier attempts had black fill in the cells.  I've attached an image of what Excel looks like, and the syntax that got there:

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Model Dimension'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/extest1.xls', sheet='mixedresults', action='CreateWorksheet', location='OverwriteAtCellRef', startingCell='A3')".
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Information Criteria'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/extest1.xls', sheet='mixedresults', action='ModifyWorksheet', location='AddRows', startingCell='A15')".
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Intraclass Correlation Coefficients'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/extest1.xls', sheet='mixedresults', action='ModifyWorksheet', location='AddRows', startingCell='A25')".
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="Estimates of Fixed Effects'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/extest1.xls', sheet='mixedresults', action='ModifyWorksheet', location='AddRows', startingCell='A35')".
    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="Estimates of Covariance Parameters'" PROCESS=ALL
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/extest1.xls', sheet='mixedresults', action='ModifyWorksheet', location='AddRows', startingCell='A45')".
    Anything that stands out here that could improve the Excel Results?  I will keep testing different variations.


    ------------------------------
    Mark Sloan
    ------------------------------



  • 29.  RE: Controlling What gets Exported to Excel

    IBM Champion
    Posted 13 days ago
    Don't specify a starting cell if you use AddRows.  It should automatically append after the last existing row.--





  • 30.  RE: Controlling What gets Exported to Excel

    Posted 10 days ago

    Thank you for all your help and patience.  I now have working syntax for pulling specific tables from SPSS into Excel.  I did do a little band-aid....the initial output would leave out the first table, whether or not I used action='Create Worksheet' or action='ModifyWorksheet'.  To get around this I realized if I write an initial table (any table), I could then just use action='Modifyworksheet' at the same startingCell='A3' to write in the table I actually want, with the remaining tables falling into place without issue (except for formatting peculiarities).  This is the code used:

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Coefficients of Determination'" PROCESS=PRECEDING  
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1.xls', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A3')".

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE= "'Model Dimension'" PROCESS=PRECEDING     
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1.xls', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A3')".

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Information Criteria'" PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A20')".

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE= "'Intraclass Correlation Coefficients'" PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1.xls', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A29')".

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Covariance Parameter Estimates'" PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1.xls', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A34')".

    SPSSINC MODIFY OUTPUT TABLES
    /IF SUBTYPE="'Parameter Estimates'" PROCESS=PRECEDING
    /CUSTOM FUNCTION="customoutputfunctions.excelexport (file='d:/spss/results1.xls', sheet='InitM1', action= 'ModifyWorksheet', startingCell='A43')".

    Basically, I write 6 tables to get the five I need.  I don't care about the weird formatting; my Excel SPSS processor just grabs the data it needs into new properly formatted tables.  If you have any thoughts on the missing first tables, I'd be interested to streamline the syntax, but it appears to be working as is now.

    Again, thank you for all your help to get through this. I anticipate much time savings on the back end!



    ------------------------------
    Mark Sloan
    ------------------------------