Data Table
Data Table using Add Rows
Example 1
Summary: Opens a data table, adds new rows with specified values, and demonstrates the use of the Add Rows platform in JMP.
Code:
// Add New Rows
// Open data table
dt = Open("data_table.jmp");
// Add New Rows
Current Data Table() <<
Add Rows(
{:location name = "Lanesboro", :Al =
3866, :Mn = 15.56, :Na = 262.95, :Br
= 0.88, :Ce = 0.45, :Co = 0.31, :Cr
= 10.57, :Cs = 0.26, :Eu = 0.04, :Fe
= 433.86, :Hf = 0.15, :La = 0.28,
:Sc = 0.12, :sm = 0.03, :U = 0.75},
{:location name = "Stockton", :al =
2789.16, :Mn = 6.6, :Na = 208.6, :Br
= 0.45, :Ce = 0.4, :Co = 0.28, :Cr
= 11.76, :Cs = 0.25, :Eu = 0.04, :Fe
= 342.8, :Hf = 0.08, :La = 0.12, :Sc
= 0.05, :Sm = 0.02, :U = 0.63}
);
Code Explanation:
- Open data table.
- Add new rows with data.
Example 2
Summary: Opens a data table, adds one row to the table, and prepares it for analysis.
Code:
// Roll Once
// Open data table
dt = Open("data_table.jmp");
// Roll Once
Current Data Table() << Add Rows( 1 );
Code Explanation:
- Open data table.
- Add one row to table.
Example 3
Summary: Opens a data table, adds rows to the current table using the ':Num Rolls' variable, and clusters variables for analysis.
Code:
// Roll Many
// Open data table
dt = Open("data_table.jmp");
// Roll Many
Current Data Table() <<
Add Rows( :Num Rolls );
Code Explanation:
- Open data table.
- Set variable
dt. - Add rows to current table.
- Use
:Num Rollsfor count.
Data Table using Column
Example 1
Summary: Simulates model responses by applying a logistic regression formula to the 'Y Simulated' column in a JMP data table, incorporating intercept and predictor variables.
Code:
// Simulate Model Responses
// Open data table
dt = Open("data_table.jmp");
// Simulate Model Responses
dt = Current Data Table();
col = Column( "Y Simulated" );
col <<
Formula(
Random Binomial(
1,
1 / (1
+Exp(
-1 * (1 + 1 * :X1 + 0.9 * :X2
+ 0.8 * :X3 + 0.7 * :X4
+0.6 * :X5 + 0.5 * :X6)
))
)
);
Code Explanation:
- Open data table.
- Set current data table.
- Select "Y Simulated" column.
- Assign formula to column.
- Use Random Binomial function.
- Set number of trials to 1.
- Calculate probability using logistic model.
- Include intercept and predictors.
- Apply exponential transformation.
- Negate and sum terms.
Example 2
Summary: Process of opening selected defects and constructing web URLs for further analysis, utilizing a loop to iterate through defect IDs.
Code:
// Open Selected Defects
Names Default To Here( 1 );
dt = Current Data Table();
defList = (Column( dt, 1 ) << get values)
[dt << Get Selected Rows];
For( i = 1, i <= N Items( defList ), i++,
Eval(
Parse(
Substitute(
"web(\!"http://sww.sas.com/cgi-bin/quick_browse?defectid=_DEF_\!")",
"_DEF_", defList[i]
)
)
)
);
Code Explanation:
- Set default names.
- Get current data table.
- Retrieve selected rows.
- Extract defect IDs.
- Loop through each defect ID.
- Construct web URL.
- Evaluate the URL.
Example 3
Summary: Runs the recoding and reorganization of data table columns, including adding coding properties and updating column selection.
Code:
dt = Open("data_table.jmp");
Column( dt, "Age" ) << Set Selected;
dt:Age << Add Column Properties( Set property( "Coding", {12, 17} ) );
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( 17, 18 );
wrc = Window( "Recode - age" );
wrc[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc[Button Box( 4 )] << Click(),
wrc[Button Box( 6 )] << Click()
);
dt << Clear Column Selection;
Column( dt, "Height" ) << Set Selected;
dt:Height << Add Column Properties( Set property( "Coding", {51, 70} ) );
dt << Begin Data Update;
dc1 = New Column( :height );
dc1 << Set Name( "height 2" );
Current Data Table() << Go to( dc1 );
Current Data Table() << Move Selected Columns( after( :height ) );
For Each Row( dc1[] = Match( :height, 51, 50, :height ) );
dc1 << Set Property( Coding, Eval List( {Col Minimum( dc1 ), Col Maximum( dc1 )} ) );
Current Data Table() << End Data Update;
dt << Clear Column Selection;
Code Explanation:
- Open data table.
- Select "Age" column.
- Add coding properties to "Age".
- Initiate recode process.
- Change value 17 to 18.
- Access recode window.
- Set combo box to third option.
- Click appropriate button based on host OS.
- Clear column selection.
- Select "Height" column.
Example 4
Summary: Runs the recoding and formatting of a data table column, specifically changing values for 'ALFRED' to 'blah' and 'AMY' to 'a2', while converting all values to titlecase.
Code:
dtBCF = Open("data_table.jmp");
Column( dtBCF, "Name" ) << Set selected;
recode = (Current Data Table() << Recode( Return ))[1];
recode << Change Value( "ALFRED", "blah" );
recode << Change Value( "AMY", "a2" );
recode << Convert to Titlecase();
recode << Set Compress Sequence( 0 );
recode << Set Script Sequence( 0 );
recode << Save to Script Window();
recode << close recode;
Code Explanation:
- Open data table.
- Select "Name" column.
- Initiate recode platform.
- Change "ALFRED" to "blah".
- Change "AMY" to "a2".
- Convert values to titlecase.
- Disable compression sequence.
- Disable script sequence.
- Save recode to script window.
- Close recode platform.
Data Table using Columns
Summary: Opens a data table and transposes specified columns in JMP, allowing for efficient analysis and manipulation of the data.
Code:
// Transpose
// Open data table
dt = Open("data_table.jmp");
// Transpose
Current Data Table() <<
Columns( :plastic, :tin, :gold )`;
Code Explanation:
- Open data table.
- Transpose specified columns.
Data Table using N Rows
Example 1
Summary: Excludes rows in a data table, starting from row 101, using the N Rows function to retrieve the total number of rows and then looping through each row to set its state as excluded.
Code:
// Set currrent data as excluded
// Open data table
dt = Open("data_table.jmp");
// Set currrent data as excluded
dt = Current Data Table();
lastRow = N Rows( dt );
For( i = 101, i <= lastRow, i++,
Row State( i ) = Excluded State( 1 )
);
Code Explanation:
- Open data table.
- Set current data as excluded.
- Get number of rows.
- Loop through rows starting from 101.
- Exclude each row.
- End loop.
Example 2
Summary: Process of clearing excluded data in a JMP data table, starting from row 101 to the end, by iterating through rows and setting their exclusion state to 'Not Excluded'.
Code:
// Clear excluded data
// Open data table
dt = Open("data_table.jmp");
// Clear excluded data
dt = Current Data Table();
lastRow = N Rows( dt );
For( i = 101, i <= lastRow, i++,
Row State( i ) = Excluded State( 0 )
);
Code Explanation:
- Open data table.
- Set current data table.
- Get number of rows.
- Loop through rows 101 to end.
- Clear exclusion for each row.
Data Table using New Column
Example 1
Summary: Adds a new column to the data table with simulated purity values generated using a Weibull distribution, and sets specification limits for quality control.
Code:
// Add Simulation Column
// Open data table
dt = Open("data_table.jmp");
// Add Simulation Column
dt = Current Data Table();
dt <<
New Column( "Simulated Purity",
Formula(
Random Weibull(
1589.7167836,
99.918708989
)
),
Set Property(
"Spec Limits",
{LSL( 99.5 ), Show Limits( 0 )}
)
);
Code Explanation:
- Open data table.
- Get current data table.
- Add new column.
- Name column "Simulated Purity".
- Define column formula.
- Use Random Weibull function.
- Set shape parameter.
- Set scale parameter.
- Set specification limits.
- Set lower specification limit.
Example 2
Summary: Recodes and rearranges a data table's sex column, utilizing New Column and Move Selected Columns functions.
Code:
dt1 = Open("data_table.jmp");
Current Data Table() << Begin Data Update;
dc1 = New Column( :sex );
dc1 << Set Name( "sex 2" );
Current Data Table() << Go to( dc1 );
Current Data Table() << Move Selected Columns( after( :sex ) );
For Each Row( dc1[] = Match( :sex, "F", "Female", "M", "Male", :sex ) );
Current Data Table() << End Data Update;
matrix1 = :sex2 << Get as Matrix();
Current Data Table() << Begin Data Update;
dc1 = Current Data Table() << New Column( "sex 2", Character, "Nominal", Formula( Match( :sex, "F", "Female", "M", "Male", :sex ) ) );
Current Data Table() << Go to( dc1 );
Current Data Table() << Move Selected Columns( after( :sex ) );
Current Data Table() << End Data Update;
Code Explanation:
- Open data table.
- Start data update.
- Create new column for sex.
- Rename new column to "sex 2".
- Navigate to new column.
- Move new column after original sex.
- For each row, recode sex values.
- End data update.
- Get new column as matrix.
- Recreate "sex 2" column with formula.
Example 3
Summary: Creates age lists from a data table, grouping names by age and generating a new table with the results.
Code:
dt = Open("data_table.jmp");
newDt = New Table( "Age Lists", New Column( "ageOld", Numeric ), New Column( "ageList", Character ) );
Current Data Table( dt );
str = "";
lastAge = 0;
For Each Row(
theName = :name;
theAge = :age;
If( :age != lastAge,
newDt << AddRow( {:ageOld = lastAge, :ageList = str} );
str = "";
);
str ||= " " || theName;
lastAge = theAge;
);
newDt << AddRow( {:ageOld = lastAge, :ageList = str} );
Close( dt, "nosave" );
Close( newDt, "nosave" );
colPlus3 = Function( {col},
{dt},
dt = col << Get Data Table;
Eval( Substitute( Expr( dt << New Column( "plus 3", formula( As Column( c ) + 3 ) ) ), Expr( c ), col ) );
);
Code Explanation:
- Open data table.
- Create new table for age lists.
- Set current data table to opened one.
- Initialize string variable for names.
- Initialize last age variable.
- Iterate through each row in data table.
- Assign name and age from current row.
- Check if current age is different from last age.
- Add row to new table with age and names list.
- Reset names list string.
- Append name to names list string.
- Update last age variable.
- Add final row to new table.
- Close original data table without saving.
- Close new data table without saving.
- Define function to add new column with values plus 3.
Example 4
Summary: Creates an age-based list by grouping names and ages from a data table, utilizing a For Each Row loop to iterate through the rows.
Code:
dt = Open("data_table.jmp");
newDt = New Table( "Age Lists", New Column( "ageOld", Numeric ), New Column( "ageList", Character ) );
Current Data Table( dt );
str = "";
lastAge = 0;
For Each Row(
theName = :name;
theAge = :age;
If( :age != lastAge,
newDt << AddRow( {:ageOld = lastAge, :ageList = str} );
str = "";
);
str ||= " " || theName;
lastAge = theAge;
);
newDt << AddRow( {:ageOld = lastAge, :ageList = str} );
Code Explanation:
- Open data table;
- Create new table "Age Lists".
- Define columns "ageOld" and "ageList".
- Set current data table to data_table.
- Initialize string variable
str. - Initialize variable
lastAgeto 0. - Loop through each row in the table.
- Assign name and age from current row.
- Check if age is different from
lastAge. - Add row to new table with
lastAgeandstr. - Reset
strto empty. - Append name to
str. - Update
lastAgeto current age. - After loop, add final row to new table.
Data Table using ColorByColumn
Example 1
Summary: Visualizes the current data table by applying color and marker by column using the 'Color Rating' column, providing an interactive representation of the data.
Code:
// Color and Mark by Color Rating
Current Data Table() <<
ColorByColumn( :Color Rating );
Current Data Table() <<
MarkerByColumn( :Color Rating );
Code Explanation:
- Access current data table.
- Apply color by column.
- Use "Color Rating" column.
- Access current data table again.
- Apply marker by column.
- Use "Color Rating" column.
Example 2
Summary: Colors and marks the current data table by region name, utilizing ColorByColumn and MarkerByColumn functions.
Code:
// Color and Mark by Region Name
Current Data Table() <<
ColorByColumn( :Region Name );
Current Data Table() <<
MarkerByColumn( :Region Name );
Code Explanation:
- Get current data table.
- Color by Region Name column.
- Get current data table again.
- Mark by Region Name column.
Example 1
Summary: Opens a data table, clears all selections and column selections, and performs principal component analysis (PCA) on variables using the 'on Correlations' option.
Code:
// On Open
Current Data Table() <<
ClearSelect;
Current Data Table() <<
ClearColumnSelection;
Code Explanation:
- Open table.
- Clear all selections.
- Clear column selections.
Example 2
Summary: Clears the current selection, row states, and column selection in a data table before performing principal component analysis (PCA) on variables using the 'on Correlations' option.
Code:
// On Open
Current Data Table() <<
ClearSelect;
Current Data Table() <<
ClearRowStates;
Current Data Table() <<
ClearColumnSelection;
Code Explanation:
- Clear current selection.
- Clear row states.
- Clear column selection.
Example 3
Summary: Clears the selection, row states, and column selection in a data table to prepare it for further analysis.
Code:
// Table Cleanup
Current Data Table() << ClearSelect;
Current Data Table() << ClearRowStates;
Current Data Table() <<
ClearColumnSelection;
Code Explanation:
- Clear selected rows.
- Clear row states.
- Clear column selection.
Example 4
Summary: Opens a data table, sets the header background and text colors for specific columns, and does not perform any statistical analysis or visualization.
Code:
Open("data_table.jmp");
Data Table("data_table"):picture << Set Header Background Color( "Medium Light YellowGreen" );
Data Table("data_table"):name << Set Header Text Color( "Medium Dark Fuchsia" );
Data Table("data_table"):name << Set Header Text Color( "Red" );
Data Table("data_table"):age << Set Header Text Color( "Dark Magenta" );
Code Explanation:
- Open data table;
- Set picture header color.
- Set name header text color.
- Override name header text color.
- Set age header text color.
Example 5
Summary: Opens a data table, customizes the header colors and text, and sets specific colors for certain columns.
Code:
Open("data_table.jmp");
Data Table("data_table"):picture << Set Header Background Color( "Medium Light YellowGreen" );
Data Table("data_table"):name << Set Header Text Color( "Medium Dark Fuchsia" );
Data Table("data_table"):name << Set Header Text Color( "Red" );
Data Table("data_table"):age << Set Header Text Color( "Dark Magenta" );
Data Table("data_table"):sex << Set Header Background Color( "Light Cyan" );
Code Explanation:
- Open data table.
- Set header background color.
- Set header text color.
- Override previous text color.
- Set header text color.
- Set header text color.
- Set header background color.
Example 6
Summary: Selects and excludes rows in a data table, clearing previous selections and hiding excluded rows.
Code:
Open("data_table.jmp");
dt = Data Table("data_table");
dt << Clear Select << Select Rows( Index( 1, 35 ) ) << Hide and Exclude;
Code Explanation:
- Open data table.
- Assign data table to variable.
- Clear previous selections.
- Select rows 1 to 35.
- Hide and exclude selected rows.
Example 7
Summary: Configures data table properties for weight and height variables, setting spec limits and enabling display of limits.
Code:
Open("data_table.jmp");
Data Table("data_table"):weight << Set Property( "Spec Limits", {LSL( 0 ), USL( 200 ), Show Limits( 1 )} );
Data Table("data_table"):height << Set Property( "Spec Limits", {LSL( 40 ), USL( 80 ), Show Limits( 1 )} );
Code Explanation:
- Open data table;
- Set weight spec limits.
- Enable weight limits display.
- Set height spec limits.
- Enable height limits display.
Example 8
Summary: Runs color marking by age in a data table, utilizing the Color or Mark by Column feature with a custom color theme and marker theme.
Code:
Open("data_table.jmp");
Data Table("data_table") << Color or Mark by Column( :age, Color( 0 ), Marker Theme( "Hollow" ) );
Code Explanation:
- Open data table.
- Select table
- Apply color by age.
- Set color theme.
- Set marker theme.
Example 9
Summary: Runs the recoding and labeling of a column in a JMP data table, utilizing the Recode Column platform to transform values based on specific conditions.
Code:
dt = Open("data_table.jmp");
dt = Data Table("data_table");
dt << Begin Data Update;
col1 = dt << New Column( dt:weight );
col1 << Set Name( "weight 2" );
dt << Move Selected Columns( {col1}, after( dt:weight ) );
dt << Recode Column(
dt:weight,
{Format( _rcNow, "Fixed Dec", 5, 0 ), Word(
1,
_rcNow,
Get Whitespace Characters() || Get Punctuation Characters( Exclude Chars( "'-" ) ),
Unmatched( _rcNow )
), Num( _rcNow ), Map Value(
_rcOrig,
{64, 1, 67, 2, 74, 3, 79, 4, 81, 5, 84, 6, 85, 7, 91, 8, 92, 9, 93, 10, 95, 11, 98, 12, 99, 13, 104, 14, 105, 15, 106, 16, 107, 17,
111, 18, 112, 19, 113, 20, 115, 21, 116, 22, 119, 23, 123, 24, 128, 25, 134, 26, 142, 27, 145, 28, 172, 29},
Unmatched( _rcNow )
)},
Target Column( col1 )
);
col1 << Remove Value Labels;
col1 << Value Labels(
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29},
{"a64", "67", "74", "79", "81", "84", "85", "91", "92", "93", "95", "98", "99", "104", "105", "106", "107", "111", "112", "113", "115",
"116", "119", "123", "128", "134", "142", "145", "172"}
);
dt << End Data Update;
valLabels = :weight 2 << get value labels;
Code Explanation:
- Open data table;
- Reference "data_table.jmp".
- Start data update.
- Create new column "weight 2".
- Rename column to "weight 2".
- Move "weight 2" after "weight".
- Recode "weight" column.
- Remove value labels from "weight 2".
- Add value labels to "weight 2".
- End data update.
Example 10
Summary: Runs the creation and repositioning of a new column in a data table, renaming it to 'Country 2' and moving it after the existing 'Country' column.
Code:
dt1 = Open("data_table.jmp");
dt = Data Table("data_table");
dt << Begin Data Update;
col1 = dt << New Column( dt:Country );
col1 << Set Name( "Country 2" );
dt << Move Selected Columns( {col1}, after( dt:Country ) );
Code Explanation:
- Open data table.
- Assign data table to variable.
- Start data update.
- Create new column from existing.
- Rename new column.
- Move new column position.
- End data update.
Example 11
Summary: Creates and recodes a new column in a data table, utilizing an external list for comparison and setting specific parameters.
Code:
dt1 = Open("data_table.jmp");
dt = Data Table("data_table");
dt << Begin Data Update;
col1 = dt << New Column( dt:Country );
col1 << Set Name( "Country 2" );
dt << Move Selected Columns( {col1}, after( dt:Country ) );
dt << Recode Column(
dt:Country,
{Choose Closest(
_rcNow,
Local( {list, dt_save = Current Data Table()},
list = Column( Open( "$SAMPLE_DATA/Birth Death.jmp", "Invisible" ), "country" ) << Get Values;
Current Data Table( dt_save );
list;
),
Max Edit Count( 2 ),
Max Edit Ratio( 0.25 ),
Min String Length( 3 )
)},
Target Column( col1 )
);
dt << End Data Update;
:Country 2 << set selected;
rows = dt << Get rows where( Contains( :Country 2, "Tunisia" ) );
list2 = :Country 2 << getvalues;
Code Explanation:
- Open data table.
- Assign data table to variable.
- Start data update.
- Create new column from existing.
- Rename new column.
- Move new column to specified position.
- Begin recoding process.
- Choose closest matching values for recoding.
- Use external data for comparison.
- Set recoding parameters.
- Apply recoding to target column.
- End data update.
- Select new column.
- Find rows containing specific value.
- Retrieve values from new column.
Example 12
Summary: Runs the principal component analysis (PCA) on variables using the on Correlations option in JMP, allowing for efficient dimensionality reduction and feature extraction.
Code:
Current Data Table( Open("data_table.jmp") );
dt = Current Data Table();
Code Explanation:
- Open data table.
- Set current data table.
Example 13
Summary: Opens a data table, creates a new private table, and assigns the first data table to a variable.
Code:
dt = Open("data_table.jmp");
xx = New Table( "test", private );
name = Data Table( 1 );
Code Explanation:
- Open data table.
- Create new table named "test".
- Set new table to private.
- Assign first data table to variable "name".
Example 14
Summary: Sorts a joined data table based on the 'Shuffle' variable, generating an output table with the sorted results.
Code:
dt2 = Open("data_table.jmp");
Current Data Table( dt2 );
Code Explanation:
- Open data table;
- Set current data table.
Data Table using Set Table Variable
Summary: Sets the current directory as the default name, assigns the current data table to a variable, and prompts the user to pick a directory.
Code:
// Set Current Directory
Names Default To Here( 1 );
dt = Current Data Table();
dt <<
Set Table Variable(
"Path", Pick Directory()
);
Code Explanation:
- Set default names to here.
- Assign current data table to dt.
- Set table variable "Path".
- Prompt user to pick directory.
Data Table using Pick File
Summary: Sets a custom CSS file for the current data table and prompts the user to select a JMP file.
Code:
// Set Custom .css file
Names Default To Here( 1 );
dt = Current Data Table();
dt <<
set table variable(
"CustomCssFile", Pick File()
);
Code Explanation:
- Set default names context.
- Get current data table.
- Set table variable.
- Prompt for CSS file.
Data Table using Color by Column
Example 1
Summary: Visualizes the data table with colors categorized by the 'Category' column, using a Jet color theme and disabling marker coloring.
Code:
// Color by Category
Current Data Table() <<
Color by Column(
Category,
Color( 1 ),
Color Theme( "Jet" ),
Marker( 0 ),
Marker Theme( "" ),
Continuous Scale( 0 ),
Reverse Scale( 0 ),
Excluded Rows( 0 )
);
Code Explanation:
- Access current data table.
- Apply color by column.
- Use 'Category' column.
- Set color index to 1.
- Choose 'Jet' color theme.
- Disable marker coloring.
- Set marker theme to none.
- Disable continuous scale.
- Disable reverse scale.
- Exclude rows setting off.
Example 2
Summary: Visualizes the Police District data table with color coding and marker styles, utilizing the Color by Column function to customize the appearance.
Code:
// Mark by Police District
Current Data Table() <<
Color by Column(
Police District,
Color( 0 ),
Color Theme( "" ),
Marker( 1 ),
Marker Theme( "Standard" ),
Continuous Scale( 0 ),
Reverse Scale( 0 ),
Excluded Rows( 0 )
);
Code Explanation:
- Access current data table.
- Apply color coding.
- Use Police District column.
- Set color index to 0.
- Clear color theme.
- Use marker style 1.
- Apply standard marker theme.
- Disable continuous scale.
- Disable reverse scale.
- Include all rows.
Example 3
Summary: Visualizes the 'Octane' column in a color-coded format using the Color by Column function, with a custom theme and continuous scale.
Code:
// Color by Octane
dt = Current Data Table() <<
Color by Column(
Octane,
Color( 1 ),
Color Theme( "Blue to Gray to Red" ),
Marker( 0 ),
Marker Theme( "" ),
Continuous Scale( 1 ),
Reverse Scale( 0 ),
Excluded Rows( 0 )
);
Code Explanation:
- Get current data table.
- Apply color by column.
- Use "Octane" column.
- Set color index to 1.
- Apply "Blue to Gray to Red" theme.
- Disable marker.
- Clear marker theme.
- Enable continuous scale.
- Disable reverse scale.
- Include all rows.
Data Table using Preferences
Example 1
Summary: Creates and formats a new column in a JMP data table, utilizing JSL scripting to set formulas and formats.
Code:
Preferences( Show History Panel in Workflow Builder( 0 ) );
w = Workflow();
w << Set Flow Name( "WFB2" );
w << Add JSL Step( "open", "dt=Open(\!"$SAMPLE_DATA/data_table.jmp\!", \!"invisible\!");" );
w << Add JSL Step(
"new column", "Data Table( \!"data_table.jmp\!" ) << New Column( \!"Column 6\!", Numeric,\!"Continuous\!",Format( \!"Best\!", 12 ));"
);
w << Add JSL Step( "formula", "Data Table( \!"data_table.jmp\!" ):Column 6 << Set Formula( :height / :weight );" );
w << Add JSL Step( "format Col 6", "Data Table( \!"data_table.jmp\!" ):Column 6 << Format( \!"Percent\!", 12, 0 );" );
w << Clear Selection();
w << Select Steps( 1, 4 );
w << Group( "1st open, formula, format" );
w << Clear Selection();
w << Add Empty Group( "next group" );
w << Add JSL Step( "JSL", "x=1200;" );
w << Add JSL Step( "JSL 2", "x / 100;" );
w << Clear Selection();
w << Start over;
w << resume;
Code Explanation:
- Set workflow history preference.
- Create new workflow.
- Name workflow "WFB2".
- Add step to open data table.
- Add step to create new column.
- Add step to set column formula.
- Add step to format column.
- Clear workflow selection.
- Select first four steps.
- Group selected steps.
Example 2
Summary: Creates and formats a new column in a JMP data table, utilizing JSL scripting to set formulas and formats.
Code:
Preferences( Show History Panel in Workflow Builder( 0 ) );
If( Host is( Windows ),
Main Menu( "File:New:Workflow" ),
Main Menu( "File:New:New Workflow" )
);
w = Workflow();
w << Set Flow Name( "WFB3" );
w << Add JSL Step( "open", "dt=Open(\!"$SAMPLE_DATA/data_table.jmp\!");" );
w << Add JSL Step(
"new column", "Data Table( \!"data_table.jmp\!" ) << New Column( \!"Column 6\!", Numeric,\!"Continuous\!",Format( \!"Best\!", 12 ));"
);
w << Add JSL Step( "formula", "Data Table( \!"data_table.jmp\!" ):Column 6 << Set Formula( :height / :weight );" );
w << Add JSL Step( "format Col 6", "Data Table( \!"data_table.jmp\!" ):Column 6 << Format( \!"Percent\!", 12, 0 );" );
w << Clear Selection();
w << Select Steps( 1, 4 );
w << Group( "1st open, formula, format" );
Preferences( Show History Panel in Workflow Builder( 1 ) );
Code Explanation:
- Set preferences for history panel.
- Check if host is Windows.
- Open new workflow.
- Create workflow object.
- Set workflow name.
- Add step to open data table.
- Add step to create new column.
- Add step to set formula for new column.
- Add step to format new column.
- Restore history panel preference.
Example 3
Summary: Creates a new column, sets its formula, and formats it in a JMP workflow, while also modifying preferences for the Workflow Builder.
Code:
Preferences( Show History Panel in Workflow Builder( 0 ), Show Enable Checkboxes( 1 ) );
w = Workflow();
w << Set Flow Name( "WFB3" );
w << Add JSL Step( "open", "dt=Open(\!"$SAMPLE_DATA/data_table.jmp\!");" );
w << Add JSL Step(
"new column", "Data Table( \!"data_table.jmp\!" ) << New Column( \!"Column 6\!", Numeric,\!"Continuous\!",Format( \!"Best\!", 12 ));"
);
w << Add JSL Step( "formula", "Data Table( \!"data_table.jmp\!" ):Column 6 << Set Formula( :height / :weight );" );
w << Add JSL Step( "format Col 6", "Data Table( \!"data_table.jmp\!" ):Column 6 << Format( \!"Percent\!", 12, 0 );" );
w << Clear Selection();
w << Group( "1st open, formula, format" );
w << Select Steps( 4 );
Preferences( Show History Panel in Workflow Builder( 1 ), Show Enable Checkboxes( 0 ) );
Code Explanation:
- Set preferences for workflow.
- Create a new workflow.
- Name the workflow "WFB3".
- Add step to open a data table.
- Add step to create a new column.
- Add step to set a formula for the new column.
- Add step to format the new column.
- Clear selected steps.
- Group first three steps together.
- Select the fourth step.
- Reset preferences for workflow.
Data Table using Local
Summary: Creates and configures a new column in a data table, renaming it to 'age 2' and setting its coding property.
Code:
dt = Open("data_table.jmp");
Local( {dt, col1},
dt = Data Table("data_table");
dt << Begin Data Update;
col1 = dt << New Column( dt:age );
col1 << Set Name( "age 2" );
dt << Move Selected Columns( {col1}, after( dt:age ) );
For Each Row( col1[] = Match( dt:age, 16, 25, dt:age ) );
col1 << Set Property( Coding, Eval List( {Col Minimum( col1 ), Col Maximum( col1 )} ) );
dt << End Data Update;
);
Code Explanation:
- Open data table.
- Define local variables
dtandcol1. - Assign "data_table" data table to
dt. - Begin data update.
- Create new column from
dt:age. - Rename new column to "age 2".
- Move new column after
dt:age. - For each row, set
col1value based ondt:age. - Set coding property for
col1. - End data update.
Data Table using Try
Example 1
Summary: Adds a new column to a data table, sets a variable, and closes the dataset without saving.
Code:
dt = Open("data_table.jmp");
Try( Current Data Table() << Add Multiple Columns( "Bad", 1, Before First ) );
x = 2;
Close( dt, nosave );
cert m = [12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17];
Code Explanation:
- Open data table;
- Try adding "Bad" column.
- Set variable x to 2.
- Close dataset without saving.
- Define matrix cert m.
Example 2
Summary: Adds a new column to a data table and sets a variable x to 2.
Code:
dt = Open("data_table.jmp");
Try( Current Data Table() << Add Multiple Columns( "Bad", 1, Before First ) );
x = 2;
Code Explanation:
- Open data table.
- Attempt to add column.
- Set variable x to 2.
Data Table using Function
Example 1
Summary: Runs data table subscription and unsubscription processes, enabling real-time updates and notifications in JMP.
Code:
Open("data_table.jmp");
MultipleGroupApp.subscribeDataTable = Function( {dt},
{subscriptionId},
subscriptionId = dt << subscribe( "sem", onClose( MultipleGroupApp.onTableClose ) );
subscriptionId;
);
MultipleGroupApp.unsubscribeDataTable = Function( {dt, subscriptionId},
dt << unsubscribe( subscriptionId, onClose )
);
MultipleGroupApp.onTableClose = Function( {dt},
dtname = dt << get name;
MultipleGroupApp.unsubscribeDataTable( dt, subscriptionId );
);
main = Function( {},
My.data = [=> ];
My.data[1] = [=> ];
My.data[1]["dt"] = MY.cdt = Current Data Table();
subscriptionId = MultipleGroupApp.subscribeDataTable( MY.cdt );
);
main();
Close( Current Data Table(), no save );
renameList = {};
f1 = Function( {dtab},
dtname = (dtab << getname());
Print( "opening" );
Print( dtname );
);
f2 = Function( {dtab},
dtname = (dtab << getname());
Print( "closing" );
Print( dtname );
);
f3 = Function( {dtab, dname},
{dtname},
dtname = ((Words( (dtab << getname()), "." ))[1]);
Insert Into( renameList, dtname );
);
Code Explanation:
- Open data table.
- Define
subscribeDataTablefunction. - Define
unsubscribeDataTablefunction. - Define
onTableClosefunction. - Define
mainfunction. - Initialize
My.datadictionary. - Assign current data table to
MY.cdt. - Subscribe to data table with
subscribeDataTable. - Call
mainfunction. - Close current data table without saving.
Example 2
Summary: Runs the subscription and unsubscription of a data table in JMP, utilizing the SingleGroupApp to manage closed tables.
Code:
dtx = Open("data_table.jmp");
closedTableList = {};
SingleGroupApp.subscribeDataTable = Function( {dt},
{subscriptionId},
subscriptionId = dt << subscribe( ""("client"), onClose( SingleGroupApp.onTableClose ) );
subscriptionId;
);
SingleGroupApp.onTableClose = Function( {dt},
If( Is Scriptable( MY.cdt ),
MY.cdt << get name;
Insert Into( closedTableList, MY.cdt );
);
If( Is Scriptable( My.data[1]["dt"] ),
My.data[1]["dt"] << get name;
Insert Into( closedTableList, My.data[1]["dt"] );
);
SingleGroupApp.unsubscribeDataTable( dt, subscriptionId );
);
SingleGroupApp.unsubscribeDataTable = Function( {dt, subscriptionId},
If( Is Scriptable( dt ),
dt << unsubscribe( subscriptionId, onClose )
)
);
main = Function( {},
My.data = [=> ];
My.data[1] = [=> ];
My.data[1]["dt"] = MY.cdt = Data Table( Current Data Table() << get name );
subscriptionId = SingleGroupApp.subscribeDataTable( MY.cdt );
);
main();
Try( Close( dtx, no save ) );
Try( dtx << unsubscribe( subscriptionId, "all" ) );
Code Explanation:
- Open data table.
- Initialize empty closedTableList.
- Define subscribeDataTable function.
- Define onTableClose function.
- Define unsubscribeDataTable function.
- Define main function.
- Initialize My.data dictionary.
- Set My.data[1]["dt"] to current data table.
- Subscribe to current data table.
- Call main function.
- Close data_table.jmp data table without saving.
- Unsubscribe from data_table.jmp data table.
Data Table using For
Summary: Runs the opening and inspection of a data table, utilizing loops to interact with the JMP environment.
Code:
For( i = 1, i <= 20, i++,
Open( "$SAMPLE_DATA/data_table.jmp", private );
w = Open( "$SAMPLE_DATA/data_table.jmp", invisible );
);
view = Current Data Table() << has data view;
Code Explanation:
- Loop starts.
- Open data table;
- Open data table;
- Increment loop counter.
- Repeat steps 2-4 until loop ends.
- Get current data table.
- Check for data view existence.
Data Table using New Script
Summary: Deletes a formula from the 'Matrix Row' column in a JMP data table, and then collapses whitespace in the resulting string.
Code:
dt = Open("data_table.jmp");
Current Data Table() << New Script( "test", Current Data Table():Name( "Matrix Row" ) << Delete Formula );
var = Collapse Whitespace( Char( dt << get property( "test" ) ) );
Code Explanation:
- Open data table;
- Access current data table.
- Create new script named "test".
- Delete formula from "Matrix Row" column.
- Get property "test" of data table.
- Convert property to string.
- Collapse whitespace in string.
- Assign result to variable var.
Data Table using New Window
Summary: Creates four windows with lineup boxes, text boxes, and column list boxes for data tables 1 and 2, demonstrating interactive features like maxSelected(1) and get selected.
Code:
dt1 = Open("data_table1.jmp");
dt2 = Open("data_table2.jmp");
nw = New Window( "Test",
Lineup Box( N Col( 2 ),
Text Box( "data_table1" ),
Text Box( "Popcorn2" ),
c1 = Col List Box( Data Table("data_table1"), all, maxSelected( 1 ), col_var = c1 << get selected ),
c2 = Col List Box( Data Table("data_table2"), all, maxSelected( 1 ), col_var2 = c2 << get selected )
)
);
nw << close window;
nw = New Window( "Test2",
Lineup Box( N Col( 2 ),
Text Box( "data_table1" ),
Text Box( "data_table2" ),
c1 = Col List Box( dt1, all, maxSelected( 1 ), col_var = c1 << get selected ),
c2 = Col List Box( dt2, all, maxSelected( 1 ), col_var2 = c2 << get selected )
)
);
nw << close window;
nw = New Window( "Test3",
Lineup Box( N Col( 2 ),
Text Box( "data_table" ),
Text Box( "Popcorn" ),
c1 = Col List Box( Data Table( dt1 ), all, maxSelected( 1 ), col_var = c1 << get selected ),
c2 = Col List Box( Data Table( dt2 ), all, maxSelected( 1 ), col_var2 = c2 << get selected )
)
);
nw << close window;
nw = New Window( "Test4",
Lineup Box( N Col( 2 ),
Text Box( "data_table" ),
Text Box( "Popcorn" ),
c1 = Col List Box( Data Table( Data Table("data_table") ), all, maxSelected( 1 ), col_var = c1 << get selected ),
c2 = Col List Box( Data Table( Data Table("data_table") ), all, maxSelected( 1 ), col_var2 = c2 << get selected )
)
);
nw << close window;
Code Explanation:
- Open data table 1;
- Open data table 2;
- Create window Test.
- Add lineup box.
- Add text box data_table1.
- Add text box data_table2.
- Add column list box for data_table1.
- Add column list box for data_table2.
- Close window Test.
- Repeat steps 3-9 for windows Test2, Test3, and Test4.
Data Table using Run Script
Summary: Creates a path diagram from a data table, allowing for customization of path styles, thickness, and transparency.
Code:
dt = Open("data_table.jmp");
dt << Run Script( "Free Text Floss Reasons" );
dt2 = Data Table("data_table");
Code Explanation:
- Open data table.
- Run script on table.
- Access new data table.