SPSS Statistics

 View Only
  • 1.  Reload / Update Open File

    Posted Thu January 07, 2021 08:00 PM

    Hello Community,

    is there a convenient way to reload an updated syntax file (or really any file) without closing the currently open version and reopening the updated file? The need occurs when I use an external editor (e.g. vim) to efficiently do complex and/or massive edits which the GUI editor does not provide.

    Alternatively, is there an approach or initiative to incorporate professional editors like vim or emacs into the GUI as can be done in several other frontends / software packages?

    Thank you for your input!

    Best,
    Aicko



    ------------------------------
    Aicko Yves Schumann
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Reload / Update Open File

    IBM Champion
    Posted Thu January 07, 2021 09:32 PM
    That;s something I would find useful - not from using an external editor but when I want to discard changes and revert to the version on disk the way you can with data.  There is no built-in way to do it, but it wouldn't be hard to write a little Python script that could go on a toolbar button to discard the active syntax window and reopen the file if it has a file name.

    --





  • 3.  RE: Reload / Update Open File

    Posted Fri January 08, 2021 09:44 AM
    From within the program (as of v27+), you can create restore points within a session. So far, that's all we have natively to approximate what you are looking for.

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



  • 4.  RE: Reload / Update Open File

    Posted Fri January 08, 2021 10:52 AM

    I agree and I have been puzzled that it does not exist for many years. It seems to be such a common-sense feature and a piece of cake to implement at the GUI level for IBM. Using Python for that is kind of an overkill, though. All it really needs to do is some diff / patch Unix commands linked to a menu item. As you say I often want to revert work, update files that I just pulled from another remote machine I have been working on, or most importantly for me, I would really like to run commands ala Ctrl+R directly from "vim". Editing files is just so much more efficient and much quicker when using a professional editor like vim or emacs.

    Aicko



    ------------------------------
    Aicko Yves Schumann
    ------------------------------



  • 5.  RE: Reload / Update Open File

    Posted Fri January 08, 2021 10:10 AM
    hi aicko,
    not sure this quite solves your problem, but here i go: i usually create syntax using an external editor, any editor, and save it as text file. then in the SPSS syntax window i use INCLUDE FILE =  to include the syntax to run. surely, whenever you make changes with the external editor you would need to save them to be INCLUDEd in the syntax.
    when needed, i save multiple versions of the syntax using the external editor, and modify the file name in the INCLUDE command, or add separate INCLUDE commands for each file. i understand now there is also INSERT which pretty much does the same thing.
    i hope you find this helpful.

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



  • 6.  RE: Reload / Update Open File

    IBM Champion
    Posted Fri January 08, 2021 10:12 AM
    I would recommend always using INSERT rather than INCLUDE as INCLUDE is obsolete and lacks some features available with INSERT.

    ------------------------------
    Jon Peck
    ------------------------------



  • 7.  RE: Reload / Update Open File

    Posted Fri January 08, 2021 11:06 AM

    Hello Eugenio,

    thank you for your suggestion!

    Unfortunately, this is a very different use case. I have a syntax file with many complex commands open. Then let's say I want to run them quickly for other variables, i.e. I would need to do a quick cut and paste with substituting hundreds of variables. These batch substitution things can be efficiently done with vim (or emacs, though I am a vi-guy) using regular expressions. Manually achieving the same result within SPSS is often impossible or would take hours of manual editing with the risk of making mistakes/typos. External editors also allow for need features like folding syntax or custom syntax highlighting of e.g. Python code or custom macros/functions; all important features that do not exist in the basic SPSS editor. Ideally, I would like to toss SPSS' editor altogether and execute commands out of vim directly. At any time I have many .sps/.sav files open and navigating between them is tedious and requires the mouse or looping through the window list (e.g. Alt+Tab). An external editor allows you to jump directly from file to file with a simple control sequence, i.e. it is much faster and does not require grabbing the mouse.

    Best,
    Aicko



    ------------------------------
    Aicko Yves Schumann
    ------------------------------



  • 8.  RE: Reload / Update Open File

    Posted Fri January 08, 2021 11:36 AM
    i see. seems what you then need is something like the code below, where you are executing the same command(s) on different sets of variables. below i show how to submit different variables, read from different files, and operate on them as a whole, or individually. the macro language is somewhat clunky and limited, but quite powerful once you figure out how to get around these limitations. you can copy and paste the code below onto your syntax window and run it. it does not read any file, it simply writes text to your screen. i hope this helps.


    define !test (indir = !charend('/') /
      infile = !charend('/') /
      vars = !charend('/') ).
    echo "* * *".
    echo !quote(!concat("Read this file: ",!indir,"\",!infile,".sav")).
    echo !quote(!concat("Run the analysis with these variables: ",!vars)).
    !do !v !in(!vars)
    echo !quote(!concat("And now one by one: ",!v)).
    !doend
    echo "* * *".
    !enddefine.

    !test indir = c:\temp / infile=file1 / vars=a b c.
    !test indir = c:\temp / infile=file2 / vars=d e f.
    !test indir = c:\temp / infile=file3 / vars=g h i.

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



  • 9.  RE: Reload / Update Open File

    IBM Champion
    Posted Fri January 08, 2021 01:03 PM
    Edited by System Fri January 20, 2023 04:30 PM
    The macro facility as shown here does provide a way to generalized syntax blocks.  Python programmability provides considerably more functionality here but might not be necessary in this case.  I don't care for the macro facility and avoid it except for simple substitutions,
    However, if you haven't discovered the SPSSINC SELECT VARIABLES extension command, you might find that useful without the need to use the macro facility explicitly.  SELECT VARIABLES creates a macro listing a set of variables as selected by explicit names and/or patterns (regular expressions), variable type and measurement level, and other metadata.
    I sometimes use Notepad++ for syntax mainly for its regular expression capabilities.  I used to use emacs a lot but seriously dislike Vim.  To each his or her own.    I think most users find the built-in editor adequate, and it has a number of advantages that an external editor could not provide, but I know some users who use Kedit for this purpose.  This is probably why the reload capability does not exist.
    I have been urging the product managers to make some improvements for the benefit of complex syntax jobs.  I suggest that you make suggestions via the Help > Give Feedback menu new in V27 or send them to me (jkpeck@gmail.com) and I will forward to the management team.
    I could write a short Python function to reload syntax files that have a backing file - either just the designated one or all of them, and this could be added as a toolbar item, so it could refresh on one click.
    I also want to point out the STATS OPEN PROJECT extension command.  It can automatically open a bunch of data, syntax, and output files and run various syntax files all from one command, so with a complex project, it can save a lot of manual setup.  It can even be set to run this automatically when Statistics is launched.
    --