Choose Language Hide Translation Bar
FN
FN
Contributor

saving global variable between JMP sessions

How I can define a variable that is recorded in JMP, so next time I open it I still have access to it?

 

For example, global variables are defined as:

 

::my_global_variable = 42;

 

 

0 Kudos
3 REPLIES 3

Re: saving global variable between JMP sessions

Try this code:

 

Names Default to Here( 1 );

save assignment = Char( ::my_global_variable = 42; );

Save Text File( "Saved Assignment.jsl", save assignment );

// either immediately execute

Include( "Saved Assignment.jsl" );

// or save character string before executing or furthe processing

save assignment = Load Text File( "Saved Assignment.jsl" );
Parse( save assignment );

 

(I did not test it.)

Learn it once, use it forever!
0 Kudos
txnelson
Super User

Re: saving global variable between JMP sessions

I will add to @markbailey response.  

JMP allows for a script to be run at startup. Check in the Scripting Guide for the version of JMP you are using for the name and location where you need to place the file.  

Here is the documentation for JMP 15

Run a Script at Start Up
You can run the same script every time you start JMP. For example, you might include the
definitions of some utility functions or a namespace that you want available throughout your
JMP session. You might also set some preferences in a startup script to keep preferences
consistent. Preferences persist across JMP sessions, but you could explicitly reset some
preferences in case they were changed at some point in the previous session.
Name the script jmpStart.jsl and place it in one of the following folders, as appropriate for
your operating system. When JMP starts, JMP looks for the jmpStart.jsl script in these folders
in the order in which they are listed here. The first one that is found is run, and the search
immediately stops.
Note: Some path names in this section refer to the “JMP” folder. On Windows, in JMP Pro, the
“JMP” folder is named “JMPPro”.
On Windows:
1. C:/Users/<username>/AppData/Roaming/SAS/JMP/15
2. C:/Users/<username>/AppData/Roaming/SAS/JMP
On macOS:
1. /Users/<username>/Library/Application Support/JMP/15
2. /Users/<username>/Library/Application Support/JMP
The jmpStart.jsl script runs only for a particular user on a computer. You can add a script
named jmpStartAdmin.jsl in one of the following places, as appropriate for your operating
system. This script is run for every user on a computer. JMP runs jmpStartAdmin.jsl first if
found. Then JMP runs jmpStart.jsl if found.
On Windows:
1. C:/ProgramData/SAS/JMP/15
2. C:/ProgramData/SAS/JMP
On macOS:
1. /Library/Application Support/JMP/15
2. /Library/Application Support/JMP

 

Note: For JMPPro  the directory path references to JMP change to JMPPro, 

 

In that file you could place a simple line:

Try( Include( "Saved Assignment.jsl" ) ); 

Everytime JMP would startup, it would look for the file, and run it if the file existed. 

Jim
Craige_Hales
Staff (Retired)

Re: saving global variable between JMP sessions

If the values are changed and need to be re-saved, consider using an add-in. Add-ins can have a script that runs when JMP starts and a script that runs when JMP stops. The add-in does not need to have an item in the menu to do this.

 

Also consider keeping the values in a data table with a column for each value. You probably only need a single row, but a 2nd row could be an alternate set of values. The data table will also provide a save prompt, so the add-in might not be needed.

Craige