<?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 make a general / variable script for splitting a data table and performing calculations? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54395#M30740</link>
    <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Sorry about the data table.&amp;nbsp; It seems to work fine on my computer, so I've simply reuploaded it.&lt;/P&gt;&lt;P&gt;I tried your script and it works except for one thing: creating the columns "date", "A" and "B" are redundant, because those columns get carried over to the new table by the split table function.&amp;nbsp; So the script becomes even simpler and works perfectly:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create a pointer variable to be able to 
// reference the current active data table
dt = Current Data Table();

// Create the split data table
dt2 = dt &amp;lt;&amp;lt; Split(
	Split By( :attribute ),
	Split( :value ),
	Output Table( "split table" ),
	Sort by Column Property
);

// Add new columns to the split data table
dt2 &amp;lt;&amp;lt; New Column( "C",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( :Name( "A" ) + :Name( "B" ) )
);
dt2 &amp;lt;&amp;lt; New Column( "D",
	Numeric,
	"Continuous",
	Format( "Percent", 12, 0 ),
	Formula( :Name( "A" ) / :Name( "C" ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
    <pubDate>Tue, 03 Apr 2018 15:52:07 GMT</pubDate>
    <dc:creator>kh</dc:creator>
    <dc:date>2018-04-03T15:52:07Z</dc:date>
    <item>
      <title>How to make a general / variable script for splitting a data table and performing calculations?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54333#M30703</link>
      <description>&lt;P&gt;I routinely perform the same data table manipulation and calculations and am interested in automating that with a script.&lt;/P&gt;&lt;P&gt;The general steps are something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="sample split.jpg" style="width: 200px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/10206i4376817310735770/image-size/small?v=v2&amp;amp;px=200" role="button" title="sample split.jpg" alt="sample split.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Split table (split column "value" by column "attribute") &amp;gt; generates a new table&lt;/LI&gt;&lt;LI&gt;Generate a new column (C) =&amp;nbsp;column A + column B&lt;/LI&gt;&lt;LI&gt;Generate new column (D)&amp;nbsp;= column A / column C&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="split.jpg" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/10207i2C34973414DDD444/image-size/medium?v=v2&amp;amp;px=400" role="button" title="split.jpg" alt="split.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, every table has a different number of rows and different values.&amp;nbsp; When I click through these functions and examine the script generated by JMP, the number of rows and values in each column are hard-coded.&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;How do I make these completely variable so I can run the script on new data tables of any size?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So far, I have a script that looks like this, but it prompts you for the number of rows, then just generates&amp;nbsp;an empty table.&amp;nbsp; I'm having a hard time finding documentation, so any help is appreciated!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "split table",
	Add Rows(),
	New Script(
		"Source",
		Data Table() &amp;lt;&amp;lt;
		Split(
			Split By( :attribute ),
			Split( :value ),
			Output Table( "split table" ),
			Sort by Column Property	) ),
	New Column( "date", Character( 1 ), "Nominal", Set Values( {""} ) ),
	New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( {""} ) ),
	New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( {""} ) ),
	New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Formula( :Name( "A" ) + :Name( "B" ) ) ),
	New Column( "D", Numeric, "Continuous",	Format( "Percent", 12, 0 ), Formula( :Name( "A" ) / :Name( "C" ) ) ) )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 15:46:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54333#M30703</guid>
      <dc:creator>kh</dc:creator>
      <dc:date>2018-04-03T15:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a general / variable script for splitting a data table and performing calculations?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54383#M30735</link>
      <description>&lt;P&gt;1. Your attached data table is corrupted.&amp;nbsp; I opened it using a text editor, and it has messages of having deleted the data.&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; From the text of your question, I think I understand how you are thinking your script structure should be doing what you want, but in fact, it will just generate an empty data table....as you have reported it does.&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp; Here is what I think you want as the starting for your script&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create a pointer variable to be able to reference 
// the current active data table
dt = Current Data Table();

// Creat the split data table
dt2 = dt &amp;lt;&amp;lt; Split(
	Split By( :attribute ),
	Split( :value ),
	Output Table( "split table" ),
	Sort by Column Property
);

// Add the new columns to the split data table
dt2 &amp;lt;&amp;lt; New Column( "date", Character( 1 ), "Nominal", Set Values( {""} ) );
dt2 &amp;lt;&amp;lt; New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( {""} ) );
dt2 &amp;lt;&amp;lt; New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( {""} ) );
dt2 &amp;lt;&amp;lt; New Column( "C",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( :Name( "A" ) + :Name( "B" ) )
);
dt2 &amp;lt;&amp;lt; New Column( "D",
	Numeric,
	"Continuous",
	Format( "Percent", 12, 0 ),
	Formula( :Name( "A" ) / :Name( "C" ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 14:43:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54383#M30735</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-04-03T14:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a general / variable script for splitting a data table and performing calculations?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54395#M30740</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;Sorry about the data table.&amp;nbsp; It seems to work fine on my computer, so I've simply reuploaded it.&lt;/P&gt;&lt;P&gt;I tried your script and it works except for one thing: creating the columns "date", "A" and "B" are redundant, because those columns get carried over to the new table by the split table function.&amp;nbsp; So the script becomes even simpler and works perfectly:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create a pointer variable to be able to 
// reference the current active data table
dt = Current Data Table();

// Create the split data table
dt2 = dt &amp;lt;&amp;lt; Split(
	Split By( :attribute ),
	Split( :value ),
	Output Table( "split table" ),
	Sort by Column Property
);

// Add new columns to the split data table
dt2 &amp;lt;&amp;lt; New Column( "C",
	Numeric,
	"Continuous",
	Format( "Best", 12 ),
	Formula( :Name( "A" ) + :Name( "B" ) )
);
dt2 &amp;lt;&amp;lt; New Column( "D",
	Numeric,
	"Continuous",
	Format( "Percent", 12, 0 ),
	Formula( :Name( "A" ) / :Name( "C" ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 15:52:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-general-variable-script-for-splitting-a-data-table/m-p/54395#M30740</guid>
      <dc:creator>kh</dc:creator>
      <dc:date>2018-04-03T15:52:07Z</dc:date>
    </item>
  </channel>
</rss>

