<?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: How to replace an entire column with new content, if it exists in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-replace-an-entire-column-with-new-content-if-it-exists/m-p/421512#M67039</link>
    <description>&lt;P&gt;Here is one method that will handle the issue where the column already exists&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

//get the unique character variable list
col9 = Column( dt, "Column 1" );
unique_char = Associative Array( col9 ) &amp;lt;&amp;lt; get keys;
nuniquechar = N Items( unique_char ); //will be 5, if categories are A, B, C, D, E
unique_aa = Associative Array( unique_char, Repeat( {.}, nuniquechar ) ); //repeat to initialize values as missing

//create new window to create multiple number edit boxes
vlbExpr = V List Box();
For( i = 1, i &amp;lt;= nuniquechar, i++,
	Insert Into( vlbExpr, Text Box( "Number for " || Char( unique_char[i] ) || ":" ) );   //i.e. "Number for A:"
	Eval(
		Eval Expr(
			Insert Into(
				vlbExpr,
				Number Edit Box(
					.,
					&amp;lt;&amp;lt;Set Function(
						Function( {this},
							unique_aa[Expr( unique_char[i] )] = this &amp;lt;&amp;lt; get
						)
					)
				)
			)
		)
	);
);

nw = New Window( "Set Values",
	&amp;lt;&amp;lt;Modal,
	vlbExpr,
	H List Box(
		Button Box( "OK", 
		
		),
		Button Box( "Cancel" )
	)
);
//Show(unique_aa);

If( Try( dt:Column 2 &amp;lt;&amp;lt; get name, "" ) != "",
	Eval( Eval Expr( dt:Column 2 &amp;lt;&amp;lt; set formula( Expr( unique_aa )[:Column 1] ) ) ),
	Eval(
		Eval Expr(
			dt &amp;lt;&amp;lt; New Column( "Column 2",
				Numeric,
				Continuous,
				&amp;lt;&amp;lt;Formula( Expr( unique_aa )[:Column 1] )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Sep 2021 04:19:43 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-09-28T04:19:43Z</dc:date>
    <item>
      <title>How to replace an entire column with new content, if it exists</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-replace-an-entire-column-with-new-content-if-it-exists/m-p/421469#M67035</link>
      <description>&lt;P&gt;This post is a follow-up and extension of the solved forum &lt;A href="https://community.jmp.com/t5/Discussions/How-to-make-a-JMP-script-to-make-a-new-window-for-user-input/m-p/419713#M66868" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following script was developed in that post:&amp;nbsp;&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 = Current Data Table();

//get the unique character variable list
col9 = Column(dt, "Column 1");
unique_char = Associative Array(col9) &amp;lt;&amp;lt; get keys;
nuniquechar = N Items(unique_char); //will be 5, if categories are A, B, C, D, E
unique_aa = Associative Array(unique_char, Repeat({.}, nuniquechar)); //repeat to initialize values as missing

//create new window to create multiple number edit boxes
vlbExpr = V List Box();
For(i = 1, i &amp;lt;= nuniquechar, i++,
	Insert Into(vlbExpr, Text Box("Number for " || Char(unique_char[i]) || ":"));   //i.e. "Number for A:"
	Eval(
		Eval Expr(Insert Into(vlbExpr, Number Edit Box(., &amp;lt;&amp;lt;Set Function(Function({this}, unique_aa[Expr(unique_char[i])] = this &amp;lt;&amp;lt; get)))))
	);
);

nw = New Window("Set Values",
	&amp;lt;&amp;lt;Modal,
	vlbExpr,
	H List Box(
		Button Box("OK", 
		
		),
		Button Box("Cancel")
	)
);
//Show(unique_aa);

Eval(EvalExpr(dt &amp;lt;&amp;lt; New Column("Column 2",
	Numeric,
	Continuous,
	&amp;lt;&amp;lt; Formula(
		Expr(unique_aa)[:Column 1]
	);
)));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If Column 2 already exists, and the user wants to replace it with a set of new values, by re-running the script and entering in a new set of values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use the update function. If Column 2 exists, the update function will be used on Column 2. Else, Column 2 will be created. as above. but I am not familiar with the Eval expression and need a better understanding of where I could put a statement like this in the script if it works out.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:37:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-replace-an-entire-column-with-new-content-if-it-exists/m-p/421469#M67035</guid>
      <dc:creator>kachveder</dc:creator>
      <dc:date>2023-06-10T23:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace an entire column with new content, if it exists</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-replace-an-entire-column-with-new-content-if-it-exists/m-p/421512#M67039</link>
      <description>&lt;P&gt;Here is one method that will handle the issue where the column already exists&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

//get the unique character variable list
col9 = Column( dt, "Column 1" );
unique_char = Associative Array( col9 ) &amp;lt;&amp;lt; get keys;
nuniquechar = N Items( unique_char ); //will be 5, if categories are A, B, C, D, E
unique_aa = Associative Array( unique_char, Repeat( {.}, nuniquechar ) ); //repeat to initialize values as missing

//create new window to create multiple number edit boxes
vlbExpr = V List Box();
For( i = 1, i &amp;lt;= nuniquechar, i++,
	Insert Into( vlbExpr, Text Box( "Number for " || Char( unique_char[i] ) || ":" ) );   //i.e. "Number for A:"
	Eval(
		Eval Expr(
			Insert Into(
				vlbExpr,
				Number Edit Box(
					.,
					&amp;lt;&amp;lt;Set Function(
						Function( {this},
							unique_aa[Expr( unique_char[i] )] = this &amp;lt;&amp;lt; get
						)
					)
				)
			)
		)
	);
);

nw = New Window( "Set Values",
	&amp;lt;&amp;lt;Modal,
	vlbExpr,
	H List Box(
		Button Box( "OK", 
		
		),
		Button Box( "Cancel" )
	)
);
//Show(unique_aa);

If( Try( dt:Column 2 &amp;lt;&amp;lt; get name, "" ) != "",
	Eval( Eval Expr( dt:Column 2 &amp;lt;&amp;lt; set formula( Expr( unique_aa )[:Column 1] ) ) ),
	Eval(
		Eval Expr(
			dt &amp;lt;&amp;lt; New Column( "Column 2",
				Numeric,
				Continuous,
				&amp;lt;&amp;lt;Formula( Expr( unique_aa )[:Column 1] )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Sep 2021 04:19:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-replace-an-entire-column-with-new-content-if-it-exists/m-p/421512#M67039</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-09-28T04:19:43Z</dc:date>
    </item>
  </channel>
</rss>

