<?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 How to make script run for each sample in a list if there are multiple entries per sample in data table. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430572#M68030</link>
    <description>&lt;P&gt;I have a data table where the same samples were measured multiple times (see example below). The samples are separated by their identifier.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 499px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37032i85ECD0837A67FEC2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my script to be able to perform the same set of calculations on each sample so I can determine control limits and make a control chart for&amp;nbsp; A, B, C, etc. I do not know the identifier of each sample. I already have a script that can do my calculations and make the charts for me, it just cannot do separate calculations for each identifier.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial through was to use some kind of loop to do this. I have a script that returns each unique identifier in a list and gives me the number of unique identifiers as a set up for the loop.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Identifiers = Column( "Identifier") &amp;lt;&amp;lt; GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set &amp;lt;&amp;lt; Get Keys;

nUnique Identifiers = N Items (Unique Identifiers);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I just can't seem to get a loop to work though. Is there a better way to do this? Or could someone show me how to do the loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using JMP 10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 18:03:45 GMT</pubDate>
    <dc:creator>J-Leonard</dc:creator>
    <dc:date>2023-06-09T18:03:45Z</dc:date>
    <item>
      <title>How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430572#M68030</link>
      <description>&lt;P&gt;I have a data table where the same samples were measured multiple times (see example below). The samples are separated by their identifier.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 499px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/37032i85ECD0837A67FEC2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my script to be able to perform the same set of calculations on each sample so I can determine control limits and make a control chart for&amp;nbsp; A, B, C, etc. I do not know the identifier of each sample. I already have a script that can do my calculations and make the charts for me, it just cannot do separate calculations for each identifier.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial through was to use some kind of loop to do this. I have a script that returns each unique identifier in a list and gives me the number of unique identifiers as a set up for the loop.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Identifiers = Column( "Identifier") &amp;lt;&amp;lt; GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set &amp;lt;&amp;lt; Get Keys;

nUnique Identifiers = N Items (Unique Identifiers);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I just can't seem to get a loop to work though. Is there a better way to do this? Or could someone show me how to do the loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using JMP 10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:03:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430572#M68030</guid>
      <dc:creator>J-Leonard</dc:creator>
      <dc:date>2023-06-09T18:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430582#M68032</link>
      <description>&lt;P&gt;There are lots of ways to do this, but one is to just add a local data filter to your existing platforms.&amp;nbsp; Here is an example using graph builder:&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);

//Open some sample data
dt = Open( "$Sample_data/big class.jmp" );

//Your code
Identifiers = Column( "age") &amp;lt;&amp;lt; GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set &amp;lt;&amp;lt; Get Keys;

nUnique Identifiers = N Items (Unique Identifiers);

//A window to hold a bunch of graphs
win = New Window("Graphs", graphbox = v list box());

//Open a graph that is filtered to only show each unique identifier
//to keep things organized add it to a single window.
for( i=1, i&amp;lt;=nUnique Identifiers, i++,
	win &amp;lt;&amp;lt; Append(&lt;BR /&gt;		//To get this script I opened graph builder and added a local data filter for one age&lt;BR /&gt;		//and then copied/pasted it here and replaced the age with 4Unique Identifiers[i]
		Graph Builder(
			Size( 534, 456 ),
			Show Control Panel( 0 ),
			Variables( X( :height ), Y( :weight ) ),
			Elements( Points( X, Y, Legend( 2 ) ) ),
			Local Data Filter(
				Close Outline( 1 ),
				Add Filter(
					columns( :age ),
					Where( :age == Unique Identifiers[i] ),
					Display( :age, N Items( 6 ) )
				)
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Oct 2021 12:24:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430582#M68032</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-10-27T12:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430682#M68037</link>
      <description>&lt;P&gt;I wonder if using the built-in control chart platforms to calculate limits and plot measures would work, especially if you assign Identifier to the By analysis role.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just don't want you to spend a lot of time scripting if it duplicates what functionality is already available.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:57:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430682#M68037</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-10-27T11:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430699#M68039</link>
      <description>&lt;P&gt;How would I be able to do additional calculations filtered by the identifier? I want to do some data manipulation and then calculate my own limits based on the data per identifier which would then be added to each of the charts, so I think any kind of filter would need to come before the final chart script. I have a script that can do that and I can post it if needed, but it is pretty long. I am really just looking for a way to make the script I already have run for each identifier rather than all of the rows in the data table&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 12:33:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430699#M68039</guid>
      <dc:creator>J-Leonard</dc:creator>
      <dc:date>2021-10-27T12:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430825#M68055</link>
      <description>&lt;P&gt;If you do not want to modify your script you could run it against a subset of each level of the identifier, like this:&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);

//Open some sample data
dt = Open( "$Sample_data/big class.jmp" );

//Your code
Identifiers = Column( "age") &amp;lt;&amp;lt; GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set &amp;lt;&amp;lt; Get Keys;

nUnique Identifiers = N Items (Unique Identifiers);

//A window to hold a bunch of graphs
win = New Window("Graphs", graphbox = v list box());

//Run an analysis on a subset of the data table for each level of a variable
for( i=1, i&amp;lt;=nUnique Identifiers, i++,
	//Make a subset of the table with only values for this level
	dt &amp;lt;&amp;lt; Select Where( :age == UniqueIdentifiers[i]);
	dtSub = dt &amp;lt;&amp;lt; Subset("Selected Rows");
	
	//run your existing script on the subset
	//For demonstration, taking a picture of the graph builder platform
	// and getting the R2 value from a linear model and adding those to a window
	pic = (gb = dtSub &amp;lt;&amp;lt; Graph Builder(
			Size( 534, 456 ),
			Show Control Panel( 0 ),
			Variables( X( :height ), Y( :weight ) ),
			Elements( Points( X, Y, Legend( 2 ) ) ),
			Local Data Filter(
				Close Outline( 1 ),
				Add Filter(
					columns( :age ),
					Where( :age == Unique Identifiers[i] ),
					Display( :age, N Items( 6 ) )
				)
			)
		)) &amp;lt;&amp;lt; Get Picture;
	graphbox &amp;lt;&amp;lt; Append( pic );
	gb &amp;lt;&amp;lt; Close Window;
	
	fm = dtSub &amp;lt;&amp;lt; Fit Model(
		Y( :height ),
		Effects( :weight ),
		Personality( "Standard Least Squares" ),
		Emphasis( "Effect Leverage" ),
		Run(
			:height &amp;lt;&amp;lt; {Summary of Fit( 1 ), Analysis of Variance( 1 ),
			Parameter Estimates( 1 ), Scaled Estimates( 0 ),
			Plot Actual by Predicted( 1 ), Plot Residual by Predicted( 1 ),
			Plot Studentized Residuals( 0 ), Plot Effect Leverage( 1 ),
			Plot Residual by Normal Quantiles( 0 ), Box Cox Y Transformation( 0 )}
		)
	);
	Wait( 0 );
	dtSum = Report( fm )[Outline Box( "Response height" )][Outline Box( "Whole Model" )][
		Outline Box( "Summary of Fit" )][Table Box( 1 )] &amp;lt;&amp;lt; Make Into Data Table;
	Report( fm ) &amp;lt;&amp;lt; Close Window;
	Rsq = dtSum:Column 2[1];
	
	graphbox &amp;lt;&amp;lt; Append( Text Box( "RSquared was " || char(Rsq) ) );
	
	dtSum &amp;lt;&amp;lt; Close Window;
	
	//close the subset
	dtSub &amp;lt;&amp;lt; Close Window;
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Oct 2021 13:38:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/430825#M68055</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-10-28T13:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to make script run for each sample in a list if there are multiple entries per sample in data table.</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/431014#M68075</link>
      <description>&lt;P&gt;Works like a charm, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 12:00:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-script-run-for-each-sample-in-a-list-if-there-are/m-p/431014#M68075</guid>
      <dc:creator>J-Leonard</dc:creator>
      <dc:date>2021-10-28T12:00:22Z</dc:date>
    </item>
  </channel>
</rss>

