cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
joshua
Level III

Parsing strings creating filter condition from excel and applying to it to datatable

Hi,

JSL: how to create a reference to a table variable inside a column formula 

 

I would like to build custom formula sheet that I can modify and apply to data table.

 

Say have a sheet-like in the attachment.

Formula Sheet

joshua_0-1612917388361.png

and would like concatenate this formula so that I can apply to selectwhere.

I come with for loop idea below but I cannot figure it out how to parse it to selectwhere

 

dt = open("$SAMPLE_DATA/Cars.jmp")


formula_Sheet = open("C:\Formula_Sheet.xlsx",
	
	Worksheet Settings(
                                            1,
     Has Column Headers( 1 )
	
));


condition_list = {}

For( i = 1, i <= Nrows( formula_Sheet ), i++,
	
	Make_col = formula_Sheet:Name("column_name")[i] ;
	filter_state = formula_Sheet:Name("filter_state")[i] ;
	filter_1 = formula_Sheet:Name("filter_1")[i] ;
	
	combined_filter_cond[i] = select where(:Name(\!""||Make_col[i]||"\!")"\!||Filter_state"\!||Filter_1"\!)";
	
	condition_list = insert(combined_filter_cond[i])
		
));

//This is the final selection code should look like dt << selectwhere((contains(:Name("Make"), "Honda") | !contains(:Name("D/P"), "Driver") | :Name("doors")>=2))

 

 

I would appreciate if admins can help on this ?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Parsing strings creating filter condition from excel and applying to it to datatable

Here is my rework of your script, to generate the selections from the cars data table.cars.PNG

names default to here(1);
dt = open("$SAMPLE_DATA/Cars.jmp");


formula_Sheet = open("C:\Formula_Sheet.xlsx",
	
	Worksheet Settings(
                                            1,
     Has Column Headers( 1 )
	
));
//formula_Sheet =data table("DATA_for_SAS_community");

theExpr = "dt << selectwhere(";

For( i = 1, i <= N Rows( formula_Sheet ), i++,
	If( formula_Sheet:column_name[i] != "",
		If( i > 1,
			theExpr = theExpr || "| "
		)
	);
	If( Contains( formula_Sheet:filter_state[i], "contain" ),
		theExpr = theExpr || formula_Sheet:filter_state[i] || "s(:Name(\!"" || formula_Sheet:column_name[i] || "\!"), \!"" || formula_Sheet:Filter_1
		[i] || "\!")",
		theExpr = theExpr || ":Name(\!"" || formula_Sheet:column_name[i] || "\!") " || formula_Sheet:filter_state[i] || formula_Sheet:Filter_1[i]
	);
);

theExpr = theExpr || ");";

Eval( Parse( theExpr ) );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Parsing strings creating filter condition from excel and applying to it to datatable

Here is my rework of your script, to generate the selections from the cars data table.cars.PNG

names default to here(1);
dt = open("$SAMPLE_DATA/Cars.jmp");


formula_Sheet = open("C:\Formula_Sheet.xlsx",
	
	Worksheet Settings(
                                            1,
     Has Column Headers( 1 )
	
));
//formula_Sheet =data table("DATA_for_SAS_community");

theExpr = "dt << selectwhere(";

For( i = 1, i <= N Rows( formula_Sheet ), i++,
	If( formula_Sheet:column_name[i] != "",
		If( i > 1,
			theExpr = theExpr || "| "
		)
	);
	If( Contains( formula_Sheet:filter_state[i], "contain" ),
		theExpr = theExpr || formula_Sheet:filter_state[i] || "s(:Name(\!"" || formula_Sheet:column_name[i] || "\!"), \!"" || formula_Sheet:Filter_1
		[i] || "\!")",
		theExpr = theExpr || ":Name(\!"" || formula_Sheet:column_name[i] || "\!") " || formula_Sheet:filter_state[i] || formula_Sheet:Filter_1[i]
	);
);

theExpr = theExpr || ");";

Eval( Parse( theExpr ) );
Jim
joshua
Level III

Re: Parsing strings creating filter condition from excel and applying to it to datatable

Hi Jim,

This is the exactly solution that I'm looking for. Thank you very much coming and providing solution for this late in the night. You are a true expert!