<?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: Formula within groups of values in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Formula-within-groups-of-values/m-p/37115#M21792</link>
    <description>&lt;P&gt;This script seems to be what you want. &amp;nbsp;It could be turned into a formula if you would prefer that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = New Table( "Untitled 13",
	Add Rows( 12 ),
	New Column( "ID",
		Character,
		"Nominal",
		Set Values( {"10", "10", "10", "10", "11", "11", "11", "11", "12", "12", "12", "12"} )
	),
	New Column( "Process Step",
		Character( 16 ),
		"Nominal",
		Set Values(
			{"Drying", "Spawned", "Drying", "Finished", "Drying", "Spawned", "Drying", "Finished", "Drying", "Spawned", "Drying",
			"Finished"}
		)
	),
	New Column( "Process Time",
		Numeric,
		"Nominal",
		Format( "h:m", 12 ),
		Input Format( "h:m" ),
		Set Values( [32400, 34200, 36000, 39600, 7200, 9000, 9900, 14400, 27000, 27900, 28800, 32400] )
	)
);

dt &amp;lt;&amp;lt; New Column( "Category", Character );

For( i = 1, i &amp;lt;= N Rows( dt ), i++,
	currID = dt:id[i];
	If( i == 1,
		spawnTime = dt:Process Time[(dt &amp;lt;&amp;lt; get rows where( dt:id == currID &amp;amp; dt:Process Step == "Spawned" ))[1]]
	);
	If( i &amp;gt; 1,
		If( dt:ID[i] != dt:ID[i - 1],
			spawnTime = dt:Process Time[(dt &amp;lt;&amp;lt; get rows where( dt:id == currID &amp;amp; dt:Process Step == "Spawned" ))[1]]
		)
	);
	If( dt:Process Time[i] &amp;lt;= spawnTime,
		dt:Category[i] = "Synthesis",
		dt:Category[i] = "Processing";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The script assumes the data are sorted by ID. &amp;nbsp;However, if the spawnTime was freshly calculated for each loop through the data, the table would not have to be sorted. &amp;nbsp;It would slow the script down, calculating the SpawnTime on each loop, but that might be a tradeoff you want to make.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2017 20:36:06 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2017-03-13T20:36:06Z</dc:date>
    <item>
      <title>Formula within groups of values</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-within-groups-of-values/m-p/37114#M21791</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table of process steps and process times for different IDs. However, some of my process steps occur more than once in the process for each ID. I would like to create a column that&amp;nbsp;separates all the process steps into either "synthesis" or "processing". These&amp;nbsp;groups would be determined based on if they occur before or after another process step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the formula to find the time of the spawn step FOR EACH ID and compare it to all the other process step times for that ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to use some sort of loop, but I am new at scripting and loops are very confusing!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to do this???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, what I have looks like this and I want to add the Category column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;ID&lt;/TD&gt;&lt;TD&gt;Process Step&lt;/TD&gt;&lt;TD&gt;Process time&lt;/TD&gt;&lt;TD&gt;Category&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;Drying&lt;/TD&gt;&lt;TD&gt;9:00&lt;/TD&gt;&lt;TD&gt;Synthesis&lt;/TD&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TD&gt;7:45&lt;/TD&gt;&lt;TD&gt;Synthesis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;Drying&lt;/TD&gt;&lt;TD&gt;8:00&lt;/TD&gt;&lt;TD&gt;Processing&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;Finished&lt;/TD&gt;&lt;TD&gt;9:00&lt;/TD&gt;&lt;TD&gt;Processing&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas??&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 19:18:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-within-groups-of-values/m-p/37114#M21791</guid>
      <dc:creator>aallman</dc:creator>
      <dc:date>2017-03-13T19:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formula within groups of values</title>
      <link>https://community.jmp.com/t5/Discussions/Formula-within-groups-of-values/m-p/37115#M21792</link>
      <description>&lt;P&gt;This script seems to be what you want. &amp;nbsp;It could be turned into a formula if you would prefer that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = New Table( "Untitled 13",
	Add Rows( 12 ),
	New Column( "ID",
		Character,
		"Nominal",
		Set Values( {"10", "10", "10", "10", "11", "11", "11", "11", "12", "12", "12", "12"} )
	),
	New Column( "Process Step",
		Character( 16 ),
		"Nominal",
		Set Values(
			{"Drying", "Spawned", "Drying", "Finished", "Drying", "Spawned", "Drying", "Finished", "Drying", "Spawned", "Drying",
			"Finished"}
		)
	),
	New Column( "Process Time",
		Numeric,
		"Nominal",
		Format( "h:m", 12 ),
		Input Format( "h:m" ),
		Set Values( [32400, 34200, 36000, 39600, 7200, 9000, 9900, 14400, 27000, 27900, 28800, 32400] )
	)
);

dt &amp;lt;&amp;lt; New Column( "Category", Character );

For( i = 1, i &amp;lt;= N Rows( dt ), i++,
	currID = dt:id[i];
	If( i == 1,
		spawnTime = dt:Process Time[(dt &amp;lt;&amp;lt; get rows where( dt:id == currID &amp;amp; dt:Process Step == "Spawned" ))[1]]
	);
	If( i &amp;gt; 1,
		If( dt:ID[i] != dt:ID[i - 1],
			spawnTime = dt:Process Time[(dt &amp;lt;&amp;lt; get rows where( dt:id == currID &amp;amp; dt:Process Step == "Spawned" ))[1]]
		)
	);
	If( dt:Process Time[i] &amp;lt;= spawnTime,
		dt:Category[i] = "Synthesis",
		dt:Category[i] = "Processing";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The script assumes the data are sorted by ID. &amp;nbsp;However, if the spawnTime was freshly calculated for each loop through the data, the table would not have to be sorted. &amp;nbsp;It would slow the script down, calculating the SpawnTime on each loop, but that might be a tradeoff you want to make.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 20:36:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Formula-within-groups-of-values/m-p/37115#M21792</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-03-13T20:36:06Z</dc:date>
    </item>
  </channel>
</rss>

