<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Having a column formula update based on a associative array referenced by a list. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Having-a-column-formula-update-based-on-a-associative-array/m-p/508378#M73717</link>
    <description>&lt;P&gt;I have a column formula that tests a product that can either pass or fail based on specification limits. An associative array is used to reference a low and high limit of different specs of the product. The issue I am having is that the user selects the product specs they want to import into the pass/fail column. They are different every time, after referenced from a different data table. The goal is to have the formula column iterate through the list of requested specs, checking if each one is inside the limits. If so, an overall pass/fail classification will be attributed. I would have this done outside the formula column, but a later part of the script is going to be refreshing that formula column repeatedly to continue analysis of passing and failing by changing the spec limit tolerances. I believe the entire calculation would need to be in the column formula itself&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached two data tables, and the work in progress script below.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);



//declare associative array for specs
specs = Associative Array();/*
//input limits file
LimitsCSV = Pick File(
	"Select The Appropriate Spec Limit Table",
	 "filepath"//Insert file path here.
	
);
//open limits file in JMP
LimitsTable = open( LimitsCSV, invisible);




//Open Current Product Testing Data
DataTable = Pick File(
	"Select The Current Product Testing Data",
	"filepath"// Insert File Path Here
	
);
//set testing data to be able to manipulate in JMP
GraphingTable = open(DataTable);

//Select the Specs you want to compare by using a COL LIST BOX
ListNumericCols = GraphingTable &amp;lt;&amp;lt; Get Column Names(numeric);
New Window("Select Wanted Specifications", &amp;lt;&amp;lt; Modal, 
	clb = Col List Box (&amp;lt;&amp;lt; Set Items (ListNumericCols))
);

ListSpecNames = clb &amp;lt;&amp;lt; Get Selected;
show(ListSpecNames); //Display for testing

//insert spec names into associative array
for (i=1,i&amp;lt; (N Items(ListSpecNames) + 1), i++,
	
	Insert Into(specs, ListSpecNames[i]);
	ColSpec = Column(LimitsTable, 1); //1 is the coolumn for spec name
	
	LimitList= {};
	
	//Insert Lower Limit onto 
	for(j=1, j &amp;lt; (nrows(LimitsTable)+1), j++,
	
		if (ColSpec[j] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 2);//14 is the column for lower limit
		MinVal = 0;
		if(ColLimit[j] &amp;gt; 0, MinVal = ColLimit[j] / 2, MinVal = ColLimit[j]*2);
		InsertInto(LimitList, MinVal );
		break();
	));
	for(k=1, k &amp;lt; (nrows(LimitsTable)+1), k++,
	
		if (ColSpec[k] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 2);//14 is the column for lower limit
		InsertInto(LimitList, ColLimit[k]);
		break();
	));
	for(l=1, l &amp;lt; (nrows(LimitsTable)+1), l++,
	
		if (ColSpec[l] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 3);//14 is the column for lower limit
		InsertInto(LimitList, ColLimit[l]);
		break();
	));
	for(m = 1, m &amp;lt; (nrows(LimitsTable)+1), m++,
		if (ColSpec[m] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 3);//14 is the column for upper limit
		MaxVal = 0;
		if(ColLimit[m] &amp;gt; 0, MaxVal = ColLimit[m] *2, MaxVal = ColLimit[m] /2 );
		InsertInto(LimitList, MaxVal );
		break();
		)	
	);	
	
	
	specs[ListSpecNames[i]] = LimitList
);

close(LimitsTable, no save);
PassBool = 1;
ColNameList = GraphingTable &amp;lt;&amp;lt; get column names(string);
newcolumn = "Pass/Fail";
if (!contains(ColNameList, NewColumn),
GraphingTable &amp;lt;&amp;lt; new column("Pass/Fail"));/*
if(((column("m1") &amp;gt;= specs["m1"][2]) &amp;amp; (column("m2") &amp;lt;= specs["m2"][3])),
		show("Pass"),
		show("Fail")
	);*/
Column(GraphingTable, "Pass/Fail") &amp;lt;&amp;lt; Set Formula(
	//counter = 0;
	
	for(i=1,i&amp;lt; (N Items(ListSpecNames) + 1), i++,
			
		if((Column(ListSpecNames[i]) &amp;gt;= specs[ListSpecNames[i]][2]) &amp;amp; (Column(ListSpecNames[i]) &amp;lt;= specs[ListSpecNames[i]][3]),
		show("Pass"),
		show("Fail");
		PassBool = 0;
		break();
		)
	) ;
	If(PassBool == 1, "Pass","Fail")
		
		
	);
	


show(specs);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and my jsl script below.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:49:31 GMT</pubDate>
    <dc:creator>JMewborn</dc:creator>
    <dc:date>2023-06-10T23:49:31Z</dc:date>
    <item>
      <title>Having a column formula update based on a associative array referenced by a list.</title>
      <link>https://community.jmp.com/t5/Discussions/Having-a-column-formula-update-based-on-a-associative-array/m-p/508378#M73717</link>
      <description>&lt;P&gt;I have a column formula that tests a product that can either pass or fail based on specification limits. An associative array is used to reference a low and high limit of different specs of the product. The issue I am having is that the user selects the product specs they want to import into the pass/fail column. They are different every time, after referenced from a different data table. The goal is to have the formula column iterate through the list of requested specs, checking if each one is inside the limits. If so, an overall pass/fail classification will be attributed. I would have this done outside the formula column, but a later part of the script is going to be refreshing that formula column repeatedly to continue analysis of passing and failing by changing the spec limit tolerances. I believe the entire calculation would need to be in the column formula itself&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached two data tables, and the work in progress script below.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);



//declare associative array for specs
specs = Associative Array();/*
//input limits file
LimitsCSV = Pick File(
	"Select The Appropriate Spec Limit Table",
	 "filepath"//Insert file path here.
	
);
//open limits file in JMP
LimitsTable = open( LimitsCSV, invisible);




//Open Current Product Testing Data
DataTable = Pick File(
	"Select The Current Product Testing Data",
	"filepath"// Insert File Path Here
	
);
//set testing data to be able to manipulate in JMP
GraphingTable = open(DataTable);

//Select the Specs you want to compare by using a COL LIST BOX
ListNumericCols = GraphingTable &amp;lt;&amp;lt; Get Column Names(numeric);
New Window("Select Wanted Specifications", &amp;lt;&amp;lt; Modal, 
	clb = Col List Box (&amp;lt;&amp;lt; Set Items (ListNumericCols))
);

ListSpecNames = clb &amp;lt;&amp;lt; Get Selected;
show(ListSpecNames); //Display for testing

//insert spec names into associative array
for (i=1,i&amp;lt; (N Items(ListSpecNames) + 1), i++,
	
	Insert Into(specs, ListSpecNames[i]);
	ColSpec = Column(LimitsTable, 1); //1 is the coolumn for spec name
	
	LimitList= {};
	
	//Insert Lower Limit onto 
	for(j=1, j &amp;lt; (nrows(LimitsTable)+1), j++,
	
		if (ColSpec[j] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 2);//14 is the column for lower limit
		MinVal = 0;
		if(ColLimit[j] &amp;gt; 0, MinVal = ColLimit[j] / 2, MinVal = ColLimit[j]*2);
		InsertInto(LimitList, MinVal );
		break();
	));
	for(k=1, k &amp;lt; (nrows(LimitsTable)+1), k++,
	
		if (ColSpec[k] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 2);//14 is the column for lower limit
		InsertInto(LimitList, ColLimit[k]);
		break();
	));
	for(l=1, l &amp;lt; (nrows(LimitsTable)+1), l++,
	
		if (ColSpec[l] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 3);//14 is the column for lower limit
		InsertInto(LimitList, ColLimit[l]);
		break();
	));
	for(m = 1, m &amp;lt; (nrows(LimitsTable)+1), m++,
		if (ColSpec[m] == ListSpecNames[i],
		ColLimit = Column(LimitsTable, 3);//14 is the column for upper limit
		MaxVal = 0;
		if(ColLimit[m] &amp;gt; 0, MaxVal = ColLimit[m] *2, MaxVal = ColLimit[m] /2 );
		InsertInto(LimitList, MaxVal );
		break();
		)	
	);	
	
	
	specs[ListSpecNames[i]] = LimitList
);

close(LimitsTable, no save);
PassBool = 1;
ColNameList = GraphingTable &amp;lt;&amp;lt; get column names(string);
newcolumn = "Pass/Fail";
if (!contains(ColNameList, NewColumn),
GraphingTable &amp;lt;&amp;lt; new column("Pass/Fail"));/*
if(((column("m1") &amp;gt;= specs["m1"][2]) &amp;amp; (column("m2") &amp;lt;= specs["m2"][3])),
		show("Pass"),
		show("Fail")
	);*/
Column(GraphingTable, "Pass/Fail") &amp;lt;&amp;lt; Set Formula(
	//counter = 0;
	
	for(i=1,i&amp;lt; (N Items(ListSpecNames) + 1), i++,
			
		if((Column(ListSpecNames[i]) &amp;gt;= specs[ListSpecNames[i]][2]) &amp;amp; (Column(ListSpecNames[i]) &amp;lt;= specs[ListSpecNames[i]][3]),
		show("Pass"),
		show("Fail");
		PassBool = 0;
		break();
		)
	) ;
	If(PassBool == 1, "Pass","Fail")
		
		
	);
	


show(specs);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and my jsl script below.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:49:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Having-a-column-formula-update-based-on-a-associative-array/m-p/508378#M73717</guid>
      <dc:creator>JMewborn</dc:creator>
      <dc:date>2023-06-10T23:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Having a column formula update based on a associative array referenced by a list.</title>
      <link>https://community.jmp.com/t5/Discussions/Having-a-column-formula-update-based-on-a-associative-array/m-p/508439#M73719</link>
      <description>&lt;P&gt;I would most likely build the formula as a string and then evaluate into the column (see&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't the most simple script to understand but run it in parts and add debug show() here and there to understand it better.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

//open limits file in JMP
LimitsTable = open("vinyl data limits.jmp", invisible);
//set testing data to be able to manipulate in JMP
GraphingTable = open("Vinyl Data.jmp");

//Select the Specs you want to compare by using a COL LIST BOX
ListNumericCols = GraphingTable &amp;lt;&amp;lt; Get Column Names(numeric);
nw = New Window("Select Wanted Specifications", &amp;lt;&amp;lt; Modal, &amp;lt;&amp;lt; return result,
	clb = Col List Box (&amp;lt;&amp;lt; Set Items (ListNumericCols))
);

ListSpecNames = nw["clb"];

// https://www.jmp.com/support/help/en/16.2/#page/jmp/associative-arrays-in-set-operations.shtml
specs = Associative Array(LimitsTable[0, 1],
	AsList(LimitsTable[0, 2::3])
);
close(LimitsTable, no save);
sel_specs = Associative Array(ListSpecNames);
specs &amp;lt;&amp;lt; Intersect(sel_specs);

if(!contains(GraphingTable &amp;lt;&amp;lt; Get Column Names("String"), "Pass/Fail"),
	GraphingTable &amp;lt;&amp;lt; new column("Pass/Fail", Character);
);

// as we have to have a formula and we have to build it dynamically, we will build it as expression
// which is based on specs associative array
// with JMP16 we can use For Each, otherwise we would have to use For
// I dont like using eval parse but in this case it is most likely easiest to build formula as string
f = "If(All(";
For Each({{spec, limits}}, specs,
	f ||= Eval Insert("^limits[1]^ &amp;lt; :^spec^ &amp;lt; ^limits[2]^ &amp;amp; ");
);
//drop last &amp;amp;
f = Left(f, Length(f) - 3);
f ||= "),"; // close all
f ||= "\!N\!t\!"PASS\!",\!"FAIL\!"
)";

Eval(EvalExpr(Column(GraphingTable, "Pass/Fail") &amp;lt;&amp;lt; Set Formula(
	Expr(Parse(f));
)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also think about using Spec Limits column properties depending on what you are doing.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 19:55:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Having-a-column-formula-update-based-on-a-associative-array/m-p/508439#M73719</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-06-13T19:55:44Z</dc:date>
    </item>
  </channel>
</rss>

