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

storing variable from file and using for max function in jsl scripting

hello members ,

am a new user just begin JSL scripting , could you provide a suggestion how to execute below need 

 

i have 2 files , 
File1 : contains data with thousands of columns (string) and row (numbers)

File2 : contains few list of columns which i created manually to pick interested column from file1 

 

my need is to do max function based on list from file 2 and create new column in file 1  

below is code which i tried and didnt work as expected.

 

dt = Open ("C:/File2.csv")

list = dt << get name; // list  = is basically few random column names from file1 = row 1 ,row2,row10, etc 

dt1 = Open ("C:/File1.jmp")

 

New column ( "max list",Numeric,Formula (Max (list)));

 

 

 

 

11 REPLIES 11
txnelson
Super User

Re: storing variable from file and using for max function in jsl scripting

I have taken a second look at your latest post, and I believe that I have a new script that will take care of the complex name issue that you exposed in that post.

// The code below this line is the that does the calculations  The code above this line would
// not normally be included
Names Default To Here( 1 ); 

// point to the large data table with lots of rows and columns
dt = Data Table( "Main" );
// If you are opening the table from a folder, this statement would be
//  dt = open("the path to the table");

// point to the second data table that contains a list of columns to be summed
dtMax = Data Table( "config" );
// If you are opening the table from a folder, this statement would be
//  dtMax = open("the path to the table");

// Just added a short pause so one can see the original tables before changing 

// Create the new columns
For( i = 1, i <= N Cols( dtMax ), i++,
	sumList = Column( dtMax, i ) << get values;
	dt << New Column( Column( dtMax, i ) << get name );
	nameList = ":\!"" || sumList[1] || "\!"n";
	For( k = 2, k <= N Rows( dtMax ), k++,
		Insert Into( nameList, ", :\!"" || sumList[k] || "\!"n" )
	);
	Column( dt, N Cols( dt ) ) << set formula( Eval( Parse( "max(" || nameList || ")" ) ) );
);
Jim
cms
cms
Level II

Re: storing variable from file and using for max function in jsl scripting

thank you .appreciate your help. it worked and resolved period /colon space issue.

Found another issue if max list and max list1 are not same counts of rows it gives error due to last row being empty in maxlist1.

MaxlistMaxlist1
office1.close:today office2.close:today 
office2.close:today office3.close:today 
office3.close:today