<?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 Re: Assign values containing in the list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761765#M93950</link>
    <description>&lt;P&gt;Thanks Jim and Jarmo!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's another method I used to figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_subset = Data Table( "subset table.jmp" );
dt_group = Data Table( "dt_groups.jmp" );
list1 = dt_group:Limits &amp;lt;&amp;lt; get values;
list2 = dt_group:ProductGroups &amp;lt;&amp;lt; get values;
list3 = dt_group:Tests &amp;lt;&amp;lt; get values;

col_names = dt_subset &amp;lt;&amp;lt; get column names( string );

aa_limits = Associative Array( dt_group:Tests &amp;lt;&amp;lt; get values, dt_group:Limits &amp;lt;&amp;lt; get values );


For Each( {val1, idx1}, list2, 
					
	For Each Row(
		dt_subset, 
									
		For Each( {val3, idx2}, list3, 

			If( Contains( val1, dt_subset:Product ), 
								
				As Column( dt_subset, list3[idx1] || "_LIMITS" ) = list1[idx1]
			
			)	
								
						
		)
	);
	
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 26 May 2024 21:47:39 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2024-05-26T21:47:39Z</dc:date>
    <item>
      <title>Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761541#M93942</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;this problem really puzzles me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to assign values from table 1 (dt_group) to table 2 (dt_subset).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So iterate through each row of Table 2 and then compare the rows of the &lt;STRONG&gt;table 2&amp;nbsp;Product&lt;/STRONG&gt; column with each row of &lt;STRONG&gt;table 1 ProductGroups&lt;/STRONG&gt; and then assign the Limits values to the _LIMITS column in table 1 if matching sting is found.&amp;nbsp;How would I script this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;table 1:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jackie__2-1716676585104.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/64516iC6B0A3991CA7F2EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jackie__2-1716676585104.png" alt="Jackie__2-1716676585104.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;table 2:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jackie__1-1716676495914.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/64515i34175DB1A06C89F4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jackie__1-1716676495914.png" alt="Jackie__1-1716676495914.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I already tried and have problem with comparing strings from both tables...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset &amp;lt;&amp;lt; get column names( string );
dt_group = Data Table( "dt_groups" );
aa_limits = Associative Array( dt_group:Tests &amp;lt;&amp;lt; get values, dt_group:Limits &amp;lt;&amp;lt; get values );

For( i = 1, i &amp;lt;= N Items( aa_limits ), i++, 
	
	If( Contains( aa_limits, col_names[i] ),
		curname = Column( dt_subset, col_names[i] ) &amp;lt;&amp;lt; get name;
						
						
		new_col = dt_subset &amp;lt;&amp;lt; New Column( (curname || "_LIMITS"),
			Numeric,
			Continuous,
			Format( "Percent", 12, 2 )
							
		);
		dt_subset &amp;lt;&amp;lt; Move Selected Columns( new_col, After( Column( dt_subset, curname ) ) );
				
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;J&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2024 22:38:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761541#M93942</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-25T22:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761551#M93943</link>
      <description>&lt;P&gt;Here is how I would do what you have specified&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_subset = Current Data Table();
col_names = dt_subset &amp;lt;&amp;lt; get column names( string );
dt_group = Data Table( "dt_groups" );
//aa_limits = Associative Array( dt_group:Tests &amp;lt;&amp;lt; get values, dt_group:Limits &amp;lt;&amp;lt; get values );

For( i = 1, i &amp;lt;= N Rows( dt_group ), i++,
	found = Contains( col_names, dt_group:Tests[i] );
	If( found  &amp;gt; 0, 
		//curname = Column( dt_subset, col_names[i] ) &amp;lt;&amp;lt; get name;
		Eval(
			Eval Expr(
				new_col = dt_subset &amp;lt;&amp;lt; New Column( col_names[found] || "_LIMITS",
					Numeric,
					Continuous,
					Format( "Percent", 12, 2 ),
					set each value( Expr( dt_group:limits[i] ) )
							
				)
			)
		);
		dt_subset &amp;lt;&amp;lt; Move Selected Columns( new_col, After( Column( dt_subset, col_names[found] ) ) );
				
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure your names in the dt_group:tests column match the column names.&amp;nbsp; You may have some extra blank spaces in column names compared to the Tests values.&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 01:29:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761551#M93943</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-05-26T01:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761553#M93944</link>
      <description>&lt;P&gt;Thanks, Jim! Not exactly what I am looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example:&lt;/P&gt;&lt;P&gt;compare Product Column row 1 of table 2 with all the strings in the first row of ProductGroups and then assign the corresponding limit value&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jackie__0-1716688263145.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/64517iEEA38AE5EC6C56C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jackie__0-1716688263145.png" alt="Jackie__0-1716688263145.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 01:52:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761553#M93944</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-26T01:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761730#M93947</link>
      <description>&lt;P&gt;Here is a completely different approach.&amp;nbsp; It uses the Join capabilities in JMP rather than attempting to do everything with loops and comparisons.&amp;nbsp; I believe it is going what you want, but please verify the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_subset = Data Table( "subset table" );
col_names = dt_subset &amp;lt;&amp;lt; get column names(  string,continuous );
dt_group = Data Table( "dt_groups" );

// Expand dt_group:ProductGroups into separate columns
dt_group &amp;lt;&amp;lt; text to columns( delimiter( "," ), columns( :ProductGroups ) );

// Stack the resulting columns
dt_group_col_names = dt_group &amp;lt;&amp;lt; get column names( string );
// Remove the first 3 columns from the list
Remove From( dt_group_col_names, 1, 3 );
// Stack data table
// → Data Table( "Stacked dt_groups" )
dt_stack_group = dt_group &amp;lt;&amp;lt; Stack(
	columns( dt_group_col_names ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Product" ),
	"Non-stacked columns"n( Keep( :Tests, :Limits ) ),
	Output Table( "Stacked dt_groups" )
);
// Get rid of the Label column
dt_stack_group &amp;lt;&amp;lt; delete columns( :Label );

// Stack the subset table
// Add a RowNum column to the table to preserve the order
dt_subset &amp;lt;&amp;lt; New Column( "RowNum", set each value( Row() ) );

dt_stack_subset = dt_subset &amp;lt;&amp;lt; Stack(
	columns(
		col_names
	),
	Source Label Column( "Tests" ),
	Stacked Data Column( "Data" ),
	Name("Non-Stacked columns")(Keep({Product, RowNum})),
	Output Table( "Stack of subset table" )
);

// Join the 2 stacked tables
dt_joined = dt_stack_subset &amp;lt;&amp;lt; Join(
	With( dt_stack_group ),
	Merge Same Name Columns,
	Match Flag( 0 ),
	By Matching Columns( :Product = :Product, :Tests = :Tests ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 0 ),
	Preserve main table order( 1 ),
	Output Table( "Joined stack data" )
);

// Split the table back to original form
dt_final = dt_joined &amp;lt;&amp;lt; Split(
	Split By( :Tests ),
	Split( :Data, :Limits ),
	Group( :RowNum ),
	Output Table( "Final" ),
	Sort by Column Property
);

// Cleanup and rearrange the Final data table
dt_final &amp;lt;&amp;lt; delete columns( :RowNum );
// Rename the columns
For( i = 2, i &amp;lt;= N Cols( dt_final ), i++,
	theName = Column( dt_final, i ) &amp;lt;&amp;lt; get name;
	If(
		Starts With( theName, "Data" ), Column( dt_final, i ) &amp;lt;&amp;lt; set name( Substr( theName, 6 ) ),
		Starts With( theName, "Limits" ),
			Column( dt_final, i ) &amp;lt;&amp;lt; set name( Substr( theName, 8 ) || "_LIMITS" )
	);
);
// Reorder the columns
For( i = Length( col_names ), i &amp;gt;= 1, i--,
	If( Try( Column( dt_final, col_names[i] || "_LIMITS" ) &amp;lt;&amp;lt; get name, "" ) != "",
		theName = ":\!"" || col_names[i] || "_LIMITS" || "\!"n";
		Eval( Parse( "dt_final &amp;lt;&amp;lt; Move Selected Columns( " || theName || ",to first);" ) );
		//dt_final &amp;lt;&amp;lt; Move Selected Columns( :"Test5^0.8_LIMITS"n,to last)
	);
	theName = ":\!"" || col_names[i] || "\!"n";
	Eval( Parse( "dt_final &amp;lt;&amp;lt; Move Selected Columns( " || theName || ",to first);" ) );
);
dt_final &amp;lt;&amp;lt; move selected columns( :Product, to first );

close( dt_stack_group, nosave);
close( dt_stack_subset, nosave);
close( dt_joined, nosave);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 May 2024 15:50:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761730#M93947</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-05-26T15:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761764#M93949</link>
      <description>&lt;P&gt;Here is my attempt. It uses the provided tables so it doesn't create any new columns and just temporarily sets formulas to calculate the values (most likely can be simplified quite a lot if subset table doesn't have pre-created columns)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt_subset = Open("$DOWNLOADS/subset table.jmp");
dt_group = Open("$DOWNLOADS/dt_groups.jmp");

aa_tests = Associative Array();

For Each Row(dt_group,
	limitname = :Tests || "_LIMITS";
	aa_tests[limitname] = Associative Array();
	aa_tests[limitname]["Groups"] = Words(:ProductGroups, " ,");
	aa_tests[limitname]["Limit"] = :Limits
);


colnames = dt_subset &amp;lt;&amp;lt; Get Column Names("Continuous", "String");
For Each({{testname, specs}}, aa_tests,
	If(!Contains(colnames, testname),
		Write("\!NNo Match: " || testname);
		Continue();
	);
	Column(dt_subset, testname) &amp;lt;&amp;lt; Formula(
		If(Contains(specs["Groups"], :Product),
			specs["Limit"];
		,
			.
		);
	);
	dt_subset &amp;lt;&amp;lt; run formulas;
	Column(dt_subset, testname) &amp;lt;&amp;lt; Delete Formula;
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 May 2024 16:02:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761764#M93949</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-05-26T16:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values containing in the list</title>
      <link>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761765#M93950</link>
      <description>&lt;P&gt;Thanks Jim and Jarmo!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's another method I used to figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt_subset = Data Table( "subset table.jmp" );
dt_group = Data Table( "dt_groups.jmp" );
list1 = dt_group:Limits &amp;lt;&amp;lt; get values;
list2 = dt_group:ProductGroups &amp;lt;&amp;lt; get values;
list3 = dt_group:Tests &amp;lt;&amp;lt; get values;

col_names = dt_subset &amp;lt;&amp;lt; get column names( string );

aa_limits = Associative Array( dt_group:Tests &amp;lt;&amp;lt; get values, dt_group:Limits &amp;lt;&amp;lt; get values );


For Each( {val1, idx1}, list2, 
					
	For Each Row(
		dt_subset, 
									
		For Each( {val3, idx2}, list3, 

			If( Contains( val1, dt_subset:Product ), 
								
				As Column( dt_subset, list3[idx1] || "_LIMITS" ) = list1[idx1]
			
			)	
								
						
		)
	);
	
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 May 2024 21:47:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Assign-values-containing-in-the-list/m-p/761765#M93950</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-05-26T21:47:39Z</dc:date>
    </item>
  </channel>
</rss>

