<?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: Adding Formula Columns based on Column Name List in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/745284#M92516</link>
    <description>&lt;P&gt;Nevermind! Issue was with my array clist not pulling the column names into a list!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Does naming a column also require an Expression Eval? The page you shared showed a Concat with Char( Array[#] ) working just fine, but I get an error trying to rename columns, code shown below. I'm not adding columns, so I'm not sure why there would be a mismatch between the N Cols and the counter in the For loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;clist = Ptable &amp;lt;&amp;lt; Get Column Names( String );
num_col = N Cols(Ptable);

For(i=3, i &amp;lt; num_col, i++,
	Column(i) &amp;lt;&amp;lt; Set Name(Char(clist[i]) || " °C"); //Error on this line
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;"Subscript Range in access or evaluation of 'clist[ /*###*/i]' , clist[/*###*/i]"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Apr 2024 19:51:00 GMT</pubDate>
    <dc:creator>BatteryTamer359</dc:creator>
    <dc:date>2024-04-08T19:51:00Z</dc:date>
    <item>
      <title>Adding Formula Columns based on Column Name List</title>
      <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724835#M90821</link>
      <description>&lt;P&gt;Hi there! I'm trying to create a script that will generate Formula columns based on if a Column Name contains the right keyword. I think I'm misusing the way lists translate strings into other functions. Currently using JMP 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Ptable = Current Data Table ();

col list = Ptable &amp;lt;&amp;lt; Get Column Names(String);

if(debug == 1, Print(col list));

For(i=1, i&amp;lt;ncols(Ptable), i++,
	If( Contains( col list[i], "Pressure"),
		New Column("Column", Numeric, "Continuous", Format("Best", 12), Set Selected);
		Column("Column") &amp;lt;&amp;lt; Set Formula(
			((15 / (0.016 *  /*###*/Num( :Resistance[1] ) /*###*/)) * Num( Column(col list[i]))
			-3.75) * 6.89476);
		Column("Column") &amp;lt;&amp;lt; Set Name(col list[i] + " (kPa)");
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 20 Feb 2024 21:32:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724835#M90821</guid>
      <dc:creator>BatteryTamer359</dc:creator>
      <dc:date>2024-02-20T21:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Formula Columns based on Column Name List</title>
      <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724839#M90823</link>
      <description>&lt;P&gt;You have to evaluate column correctly there. Expr(NameExpr(AsColumn())) is one option&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

mycol1 = "height";
mycol2 = "weight";

Eval(EvalExpr(
	new_col = dt &amp;lt;&amp;lt; New Column("Col", numeric, continuous, formula(
		Expr(NameExpr(AsColumn(dt, mycol1))) * Expr(NameExpr(AsColumn(dt, mycol2)))
	))	
));


show(new_col &amp;lt;&amp;lt; get formula);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&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-Archived/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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 22:08:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724839#M90823</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-02-20T22:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Formula Columns based on Column Name List</title>
      <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724841#M90824</link>
      <description>&lt;P&gt;Here is a modification of your code using the Big Class data table as an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

Open( "$SAMPLE_DATA/big class.jmp" );
debug = 1;

Ptable = Current Data Table();

col list = Ptable &amp;lt;&amp;lt; Get Column Names( String );

If( debug == 1,
	Print( col list )
);

// Columns are going to be added to the data table.  The For() clause
// will change the end point of the looping if ncols() is in the 
// termination value
ncolumns = N Cols( Ptable );

For( i = 1, i &amp;lt;= ncolumns, i++,
	If( Contains( col list[i], "eight" ), 
	// The formula equation needs to be fully parsed before applying it to
		// the columns definition
		Eval(
			Substitute(
					Expr(
						New Column( col List[i] || " (kPa)",
							Numeric,
							"Continuous",
							Format( "Best", 12 ),
							Set Selected,
							Formula(
								(((15 / (0.016 * Num( :age[1] ))) * Num( _col_ )) - 3.75) * 6.89476
							)
						)
					),
				Expr( _col_ ), parse(col list[i] )
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 22:23:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/724841#M90824</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-02-20T22:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Formula Columns based on Column Name List</title>
      <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/745284#M92516</link>
      <description>&lt;P&gt;Nevermind! Issue was with my array clist not pulling the column names into a list!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;Does naming a column also require an Expression Eval? The page you shared showed a Concat with Char( Array[#] ) working just fine, but I get an error trying to rename columns, code shown below. I'm not adding columns, so I'm not sure why there would be a mismatch between the N Cols and the counter in the For loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;clist = Ptable &amp;lt;&amp;lt; Get Column Names( String );
num_col = N Cols(Ptable);

For(i=3, i &amp;lt; num_col, i++,
	Column(i) &amp;lt;&amp;lt; Set Name(Char(clist[i]) || " °C"); //Error on this line
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;"Subscript Range in access or evaluation of 'clist[ /*###*/i]' , clist[/*###*/i]"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2024 19:51:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/745284#M92516</guid>
      <dc:creator>BatteryTamer359</dc:creator>
      <dc:date>2024-04-08T19:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Formula Columns based on Column Name List</title>
      <link>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/745286#M92517</link>
      <description>&lt;P&gt;Evaluation isn't required when setting the name. You have other issue in your code:&lt;/P&gt;
&lt;P&gt;This part of your code doesn't really do anything&lt;/P&gt;
&lt;LI-CODE lang="jsl"&gt;clist = {Ptable &amp;lt;&amp;lt; Get Column Names( String )};&lt;/LI-CODE&gt;
&lt;P&gt;Remove {} around the &amp;lt;&amp;lt; Get Column Names and then it should work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

clist = dt &amp;lt;&amp;lt; Get Column Names(String);
num_col = N Cols(dt);

For(i = 3, i &amp;lt; num_col, i++,
	Column(i) &amp;lt;&amp;lt; Set Name(Char(clist[i]) || " °C"); //Error on this line
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Apr 2024 19:53:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Adding-Formula-Columns-based-on-Column-Name-List/m-p/745286#M92517</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-04-08T19:53:32Z</dc:date>
    </item>
  </channel>
</rss>

