<?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: Creating new columns and inserting formula based on the original column cells in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49240#M27991</link>
    <description>&lt;P&gt;The :Name() function is designed to handle this issue.&amp;nbsp; Below is a modification I made to your script that I believe will solve the issue.&amp;nbsp; I have not tested this modification, but I think it will work.&amp;nbsp; If not, you should be able to see what I am attempting to do, and you should be able to get it to work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

col_list = dt &amp;lt;&amp;lt; get column names( string );

For( i = 13, i &amp;lt;= N Items( col_list ), i++,
	Eval(
		Substitute(
				Expr(
					Column(col_list[i])  &amp;lt;&amp;lt; Data Type( Character );
					dt &amp;lt;&amp;lt; Add Multiple Columns( __NewColName__, 1, after( __OrigCol__ ), Numeric );
					Column( __NewColName__ ) &amp;lt;&amp;lt; set formula( If( Contains( __OrigCol__, "&amp;lt;" ), 1, 0 ) );
				),
			Expr( __NewColName__ ), col_list[i] || "_Code" ,
			Expr( __OrigCol__ ), Parse( ":Name(\!"" || col_list[i] || "\!:)" )
		)
	)
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Jan 2018 17:11:39 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2018-01-04T17:11:39Z</dc:date>
    <item>
      <title>Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49211#M27969</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm an inexperienced JMP scriptor and I'm&amp;nbsp;trying to write my first larg(er) script.&amp;nbsp;I'm having trouble with one part. Here's what I'm trying to do: I have various data tables that I will use this script on. I would like the script to look at all of the columns, excluding the first column (column and row numbers will vary for each data table) and create a new column for each column already present in the table. I would like the name of each of the new columns to be the same as each of the original&amp;nbsp;columns but with a "_code" at the end, and preferably be positioned next to the&amp;nbsp;original&amp;nbsp;column in the table. Within each new column I would like the formula to be an if/then statement. If "Column A" has the text "&amp;lt;" in the cell, then 0, otherwise 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope my explanation makes sense.&amp;nbsp;I've posted my script although it seems to break at line 8 and I'm not sure why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lacey&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;Names Default To Here( 1 );

dt = Current Data Table();

col_list = dt &amp;lt;&amp;lt; get column names( string );

For( i = 2, i &amp;lt;= nitems( col_list ), i++,
	
		data_col = ":" || col_list[i];
		
		code_col = col_list[i] || "_Code";
		
		str = evalinsert (
		
			"\[dt &amp;lt;&amp;lt; New Colum ("^code_col^", Numeric, Continuous,
			Format("Best",12),
			Formula(If( Contains( "^code_col^", "&amp;lt;" ),
	0,
	1
)));
				
			);]\");
			
			eval(parse(str));
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 05:11:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49211#M27969</guid>
      <dc:creator>Lharbicht</dc:creator>
      <dc:date>2018-01-04T05:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49212#M27970</link>
      <description>&lt;P&gt;Here is a modification of your code that I believe meets all of your needs.&amp;nbsp; One item that I had to deal with, is that the columns that you start with (2-13) have to be character, so the formula does not error out.&amp;nbsp; The Column 13 does error out the script, since it is a formula column that can not be changed to character, because as soon as it runs it's formula, it will force the column to be numeric.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

col_list = dt &amp;lt;&amp;lt; get column names( string );

For( i = 13, i &amp;lt;= N Items( col_list ), i++,
	Eval(
		Substitute(
				Expr(
					Column(col_list[i])  &amp;lt;&amp;lt; Data Type( Character );
					dt &amp;lt;&amp;lt; Add Multiple Columns( __NewColName__, 1, after( __OrigCol__ ), Numeric );
					Column( __NewColName__ ) &amp;lt;&amp;lt; set formula( If( Contains( __OrigCol__, "&amp;lt;" ), 1, 0 ) );
				),
			Expr( __NewColName__ ), col_list[i] || "_Code",
			Expr( __OrigCol__ ), Parse( ":" || col_list[i]  )
		)
	)
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 06:32:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49212#M27970</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-04T06:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49222#M27978</link>
      <description>&lt;P&gt;That worked great! Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It was my mistake that I left that "column 13" in&amp;nbsp;the datatable. That was just me making sure my if then statement was working and I forgot to delete it when I posted it online. So I just deleted that out of my datatable, changed the 13 to a 2 in the wonderful script you sent and then it worked like a charm.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lacey&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 14:03:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49222#M27978</guid>
      <dc:creator>Lharbicht</dc:creator>
      <dc:date>2018-01-04T14:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49226#M27982</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I went to try the script on a new data table and I ran into a problem with my column names.&amp;nbsp;I deal with environmental data, and many times the analyte names (ie. column names) will have symbols in the name such as "-", "[", "]", "(", ")", and/or ",". When I ran the script it errored on the first column which was "3-Methyl-1-butene". &amp;nbsp;Is there a fix for this?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lacey&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 15:27:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49226#M27982</guid>
      <dc:creator>Lharbicht</dc:creator>
      <dc:date>2018-01-04T15:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49240#M27991</link>
      <description>&lt;P&gt;The :Name() function is designed to handle this issue.&amp;nbsp; Below is a modification I made to your script that I believe will solve the issue.&amp;nbsp; I have not tested this modification, but I think it will work.&amp;nbsp; If not, you should be able to see what I am attempting to do, and you should be able to get it to work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

col_list = dt &amp;lt;&amp;lt; get column names( string );

For( i = 13, i &amp;lt;= N Items( col_list ), i++,
	Eval(
		Substitute(
				Expr(
					Column(col_list[i])  &amp;lt;&amp;lt; Data Type( Character );
					dt &amp;lt;&amp;lt; Add Multiple Columns( __NewColName__, 1, after( __OrigCol__ ), Numeric );
					Column( __NewColName__ ) &amp;lt;&amp;lt; set formula( If( Contains( __OrigCol__, "&amp;lt;" ), 1, 0 ) );
				),
			Expr( __NewColName__ ), col_list[i] || "_Code" ,
			Expr( __OrigCol__ ), Parse( ":Name(\!"" || col_list[i] || "\!:)" )
		)
	)
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:11:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49240#M27991</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-04T17:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new columns and inserting formula based on the original column cells</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49244#M27993</link>
      <description>&lt;P&gt;Yes, I got that to work. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 17:52:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-new-columns-and-inserting-formula-based-on-the-original/m-p/49244#M27993</guid>
      <dc:creator>Lharbicht</dc:creator>
      <dc:date>2018-01-04T17:52:51Z</dc:date>
    </item>
  </channel>
</rss>

