SPSS Statistics

SPSS Statistics

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


#Analytics
#SPSSStatistics
#Analyticstools
 View Only
  • 1.  decreased performance over many loops within !macro language

    Posted 06/04/26 03:28 PM

    Looking for help solving the following problem, which I will try to describe with edited in code. Question is at the end.

    I have the following setup within the SPSS macro language:

    ** start.

    !let !pv = X

    !let !rwgt = Y

    !do !p = 1 !to !pv.

    get file with !n cases.

    sort cases by sortvar (40 groups).

    oms to output regression results to file Output(!p)

    !do !r = 1 to !!rwgt

    split file by sortvar

    run a regression

    split file off

    !doend.

    omsend.

    dataset close.

    Post-process the !rwgt results for !pv using the files created with OMS.

    omsend.

    dataset close.

    !doend.

    ** end.

    the macro runs fine with relatively small !n and values for !p and !r, but two problems:

    1. as it makes its way through the !p's, performance degrades noticeably. each subsequent !pv cycle seems to take 1.5x - 2.0x the previous cycle.
    2. i need to run this on a file with !n = 200,000, !pv = 20 and !rwgt =250 and it completely stalls at around !p = 10, never completing.

    i tried looking for help with OpenAI, but i received no useful hints.

    i realize it's a memory problem, which is why is why i add the omsend and dataset close statements at the end of each !pv loop, but this has done nothing to speed up or complete the run.

    i would welcome any suggestions, and would be happy to share the full code and data file if that helps.

    thank you!

    eugene



    ------------------------------
    Eugenio Gonzalez
    ------------------------------


  • 2.  RE: decreased performance over many loops within !macro language

    Posted 06/04/26 04:37 PM

    I can't tell very much from what is here, but here are a few thoughts.

    Use SET MPRINT ON. at the start to see what the actual expanded code looks like. 

    The macro will be fully expanded before any of the generated code is run.  There might be a lot of code generated then that might choke the command queue (technical term :-))

    If you are generating a lot of output in the Viewer, you might want to close the Viewer periodically so that it doesn't consume all the memory or get tied up in handling a huge number of objects.

    You might use VIEWER=NO  on the OMS command to avoid writing the output to the Viewer.  It appears that you are writing the output to a file but not suppressing it in the Viewer.

    If you can use Python external mode to run the code, that could be a big speedup.  Some years ago (actually quite a few years ago), I worked with a customer who was running many tens of thousands of regressions but needed only a little bit of the output.  Converting it to use external mode  greatly sped it up - more than an order of magnitude improvement, though I don't remember the exact details.  There is no Viewer in external mode.



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



  • 3.  RE: decreased performance over many loops within !macro language

    Posted 06/04/26 06:15 PM

    hi jon,

    as always, thanks for the quick reply.

    here are answers to your comments/questions:

    1. except for a few before the regressions are run, all the regression OMS commands have viewer = NO to suppress the output to the spv file.

    2. the MPRINT ON shows nothing suspect, at least that i can see

    3. there is a lot of code generated, but if it gets through the first PV in an ok time, why/how could there be a "choke" in the command line?

    4. i also turned off the autorecovery of files and there was no change in performance.

    5. i also close the output window and open a blank new one a the start of the run.

    clearly something is accumulating somewhere, but what could it be, and how can i clear it...?

     



    ------------------------------
    Eugenio Gonzalez
    ------------------------------



  • 4.  RE: decreased performance over many loops within !macro language

    Posted 06/04/26 07:47 PM
    Since  you are suppressing Viewer output, that shouldn't be an issue.  If there isn't much going there, then opening a new one regularly shouldn't be an issue either.  Turning off autorecovery was a good idea.

    If the syntax editor has a very large amount of code in it, it gets sluggish, but the macro expansion would happen in the backend, and even if the SE is slow, that shouldn't affect the backend processing.

    So that makes me wonder whether there is something about the actual data that is slowing things down.  Could  you try processing the files in reverse order to see if there might be something about the later files causing the problem?

    Another issue might be environmental - disk space, virtual memory exhaustion, ...?  If you watch the job run in the Task Manager - click on the performance tab or the details tab and the spssengine and stats processes.






  • 5.  RE: decreased performance over many loops within !macro language

    Posted 06/05/26 10:02 AM

    Hello Eugenio.  Please show us what the REGRESSION command looks like where you have "run a regression" in your pseudo-code.  I'm thinking of the so-called XY problem, and wondering if there could be a more efficient way to achieve what you want to do.  Thanks for clarifying.  

    Cheers,
    Bruce



    ------------------------------
    Bruce Weaver
    ------------------------------



  • 6.  RE: decreased performance over many loops within !macro language

    Posted 06/05/26 06:55 PM
    hi bruce,

    thanks for your interest, and for the reference to the XY problem.

    the full macro is attached. the regression command within the loop appears in lines 455 - 470.

    the analysis requires to jackknife the results from 20 imputations (npv = 20) using 250 replicate weights.

    this macro is distributed as part of the IEA's IDB Analyzer available from www.iea.nl.

    i hope this provides useful additional information.

    thank you.

    ==================================
    Eugenio Gonzalez
    Sr. Research Director
    TIMSS & PIRLS International Study Center
    Boston College





  • 7.  RE: decreased performance over many loops within !macro language

    Posted 06/08/26 07:23 AM

    hi bruce,

    here are the attachments.

    e.



    ------------------------------
    Eugenio Gonzalez
    ------------------------------

    Attachment(s)

    txt
    test_LR_20pvs_SPSS.sps.txt   770 B 1 version
    txt
    JB_RegGP_new3.ieasps.txt   46 KB 1 version


  • 8.  RE: decreased performance over many loops within !macro language

    Posted 06/15/26 12:26 PM

    hi,

    none of the suggestions have provided additional information or solved the problem.

    before filing in the "cold case" folder, any additional suggestions?

    thank you!

    e.



    ------------------------------
    Eugenio Gonzalez
    ------------------------------