cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Terelaloca
Level I

How do I save subsets to separate folders with script

I have created a script that will import and excel file and perform an analysis that will produce 3 subsets. Each subset needs to be a different folder but I want the subsets to have the same name as the excel file that was imported to create the subset. How would I do this or at least name each subset a specific name and save them to different folders.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I save subsets to separate folders with script

Here is an example of one way to do this

// Open a file and create 2 subsets and then save all 3 files to 
// different folders, keeping the files open in the JMP session,
// and with their original name, but naming each subset in their
// folders where they are saved

Names Default To Here( 1 );

// open the Big Class data table.
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Create subset one with all Males, letting JMP provide the new data table name
dt << select where( :sex == "M" );
dtA = dt << subset( selected columns( 0 ), selected rows( 1 ) );

// Create subset two with all Females, giving JMP the name of the new table
dt << select where( :sex == "F" );
dtB = dt << subset( selected columns( 0 ), selected rows( 1 ), Output Table( "All Females" ) );

// The Save() function automatically changes the name of the data table being saved
// to the name being specified in the file name specified in the Path of the Save() 
// function.  Therefore to keep the original table the original name, it has to be 
// renamed back to the original name.
holdName = dt << get name;
dt << save( "C:/folderA/MyName.jmp" );
dt << set name( holdName );

// Repeat the save for the first subset
holdName = dtA << get name;
dtA << save( "C:/folderB/MyName.jmp" );
dtA << set name( holdName );

// Repeat for the second subset.  The name of this subset has been specifically provided
// so the handling of this can be a little different
Data Table( "All Females" ) << save( "C:/folderC/MyName.jmp" );
Data Table( "MyName" ) << set name( "All Females" );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How do I save subsets to separate folders with script

Here is an example of one way to do this

// Open a file and create 2 subsets and then save all 3 files to 
// different folders, keeping the files open in the JMP session,
// and with their original name, but naming each subset in their
// folders where they are saved

Names Default To Here( 1 );

// open the Big Class data table.
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Create subset one with all Males, letting JMP provide the new data table name
dt << select where( :sex == "M" );
dtA = dt << subset( selected columns( 0 ), selected rows( 1 ) );

// Create subset two with all Females, giving JMP the name of the new table
dt << select where( :sex == "F" );
dtB = dt << subset( selected columns( 0 ), selected rows( 1 ), Output Table( "All Females" ) );

// The Save() function automatically changes the name of the data table being saved
// to the name being specified in the file name specified in the Path of the Save() 
// function.  Therefore to keep the original table the original name, it has to be 
// renamed back to the original name.
holdName = dt << get name;
dt << save( "C:/folderA/MyName.jmp" );
dt << set name( holdName );

// Repeat the save for the first subset
holdName = dtA << get name;
dtA << save( "C:/folderB/MyName.jmp" );
dtA << set name( holdName );

// Repeat for the second subset.  The name of this subset has been specifically provided
// so the handling of this can be a little different
Data Table( "All Females" ) << save( "C:/folderC/MyName.jmp" );
Data Table( "MyName" ) << set name( "All Females" );
Jim
Terelaloca
Level I

Re: How do I save subsets to separate folders with script

Thank you so much! This was incredibly helpful

 

David_Burnham
Super User (Alumni)

Re: How do I save subsets to separate folders with script

In addition to @txnelson's extensive answer, you might like to take a look at the function ConvertFilePath.  Although, as the name suggests, it can be used to convert file paths (e.g. from Windows to MacOS formats, or from relative to full paths), I like it because it allows me to manipulate file paths whilst keeping file name and directory information separate, without having to worry about string concatenation.

 

e.g.

 

projectHomeFolder = FilePathDefinitions:getProjectHome();
path = convertFilePath("Master_Table.jmp",base(projectHomeFolder));
-Dave