<?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: Scripting the same output for all levels of a categorical variable in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910536#M106957</link>
    <description>&lt;P&gt;Here are three options to create Tab Box from data table using grouping column. If you have JMP18+ (I think), last one is definitely the most simple one&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Using subsets
dt_subsets = dt &amp;lt;&amp;lt; Subset(
	By(:age),
	Linked,
	Selected Columns Only(0),
	All Rows(1),
	Invisible
);

nw = New Window("Subsets",
	tb = tab box()
);
dists = {};
For Each({dt_subset}, dt_subsets,
	tb &amp;lt;&amp;lt; Insert(Tab Page Box(Title(dt_subset &amp;lt;&amp;lt; get name),
		dt_subset &amp;lt;&amp;lt; Distribution(
			Continuous Distribution(Column(:weight)),
			Nominal Distribution(Column(:age))
		);	
	));
);
tb &amp;lt;&amp;lt; Set Selected(1);


// Using Where in platform
nw = New Window("Where",
	tb = tab box()
);
groups = Associative Array(Column(dt, "age")) &amp;lt;&amp;lt; get keys;

dists = {};
For Each({group}, groups,
	tb &amp;lt;&amp;lt; Insert(Tab Page Box(Title("age=" || Char(group)),
		dist = dt &amp;lt;&amp;lt; Distribution(
			Continuous Distribution(Column(:weight)),
			Nominal Distribution(Column(:age)),
			Where(:age == group)
		);
	));
	(Report(dist) &amp;lt;&amp;lt; Top Parent)[TextBox(1)] &amp;lt;&amp;lt; Visibility("Collapse"); // to hide Where(... textbox
);
tb &amp;lt;&amp;lt; Set Selected(1);


// Using By in platform
dist = dt &amp;lt;&amp;lt; Distribution(
	Group Options(Layout("Arrange in Tabs")),
	Continuous Distribution(Column(:weight)),
	Nominal Distribution(Column(:age)),
	By(:age)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Oct 2025 14:24:44 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2025-10-30T14:24:44Z</dc:date>
    <item>
      <title>Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910524#M106955</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a script that performs some calculations, runs some platforms and extracts certain output, and then builds a tab box in a new window. I want to do all of this for each level of some categorical variable that the user specified in my dialog box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently I create individual subsets of the data based on my grouping variable, and then loop through each of those datasets:&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dtSubset = dt &amp;lt;&amp;lt; Subset( By( Eval( groupVar ) ), Linked, Selected Columns Only( 0 ), All Rows( 1 ), Invisible );

For( i = 1, i &amp;lt;= N Items( unique_groups ), i++,
dt_i = dtSubset[i];

...some code to do stuff
&lt;BR /&gt;...append output as a new tab box in my window
);&lt;/CODE&gt;&lt;/PRE&gt;
Essentially all I am doing is coding up my own analysis and wanting a 'By' variable. I am wondering if there is a better or more efficient way to go about this? The main thing I want with the code is to have the output I create be specific for each level, while also still maintaining a connection to the original data table (meaning the plots in my output are interactive still).&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;As you can see, I create the subsets as Invisible and then within my code I close them at the end of each iteration of the loop.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thanks,&lt;/DIV&gt;
&lt;DIV&gt;Robert&lt;/DIV&gt;</description>
      <pubDate>Thu, 30 Oct 2025 14:06:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910524#M106955</guid>
      <dc:creator>rcast15</dc:creator>
      <dc:date>2025-10-30T14:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910534#M106956</link>
      <description>&lt;P&gt;Is there a reason for not using By variable within the platforms?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 14:12:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910534#M106956</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-10-30T14:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910536#M106957</link>
      <description>&lt;P&gt;Here are three options to create Tab Box from data table using grouping column. If you have JMP18+ (I think), last one is definitely the most simple one&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Using subsets
dt_subsets = dt &amp;lt;&amp;lt; Subset(
	By(:age),
	Linked,
	Selected Columns Only(0),
	All Rows(1),
	Invisible
);

nw = New Window("Subsets",
	tb = tab box()
);
dists = {};
For Each({dt_subset}, dt_subsets,
	tb &amp;lt;&amp;lt; Insert(Tab Page Box(Title(dt_subset &amp;lt;&amp;lt; get name),
		dt_subset &amp;lt;&amp;lt; Distribution(
			Continuous Distribution(Column(:weight)),
			Nominal Distribution(Column(:age))
		);	
	));
);
tb &amp;lt;&amp;lt; Set Selected(1);


// Using Where in platform
nw = New Window("Where",
	tb = tab box()
);
groups = Associative Array(Column(dt, "age")) &amp;lt;&amp;lt; get keys;

dists = {};
For Each({group}, groups,
	tb &amp;lt;&amp;lt; Insert(Tab Page Box(Title("age=" || Char(group)),
		dist = dt &amp;lt;&amp;lt; Distribution(
			Continuous Distribution(Column(:weight)),
			Nominal Distribution(Column(:age)),
			Where(:age == group)
		);
	));
	(Report(dist) &amp;lt;&amp;lt; Top Parent)[TextBox(1)] &amp;lt;&amp;lt; Visibility("Collapse"); // to hide Where(... textbox
);
tb &amp;lt;&amp;lt; Set Selected(1);


// Using By in platform
dist = dt &amp;lt;&amp;lt; Distribution(
	Group Options(Layout("Arrange in Tabs")),
	Continuous Distribution(Column(:weight)),
	Nominal Distribution(Column(:age)),
	By(:age)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Oct 2025 14:24:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910536#M106957</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-10-30T14:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910586#M106964</link>
      <description>&lt;P&gt;Expanding on Jarmo's By Group example, here is one that creates the Tab Window your output has.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = Open("$SAMPLE_DATA/Big Class.jmp");


// Using By in platform
dist = dt &amp;lt;&amp;lt; Distribution(Invisible,
	Group Options(Layout("Arrange in Tabs")),
	Continuous Distribution(Column(:weight)),
	Nominal Distribution(Column(:age)),
	By(:age)
);

// Create a new window and add tabs for each age
nw = New Window( "Tabs",
	tabb = Tab Box();
);

For( i = 1, i &amp;lt;= N Items( dist ), i++,
	display = Report( dist[i] );
	theByGroup = display[Outline Box( 1 )] &amp;lt;&amp;lt; get title;
	tabb &amp;lt;&amp;lt; append( Tab Page Box( Title( theByGroup ), display ) );
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1761843436312.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/86070iA2B4B15C74E4D9AB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1761843436312.png" alt="txnelson_0-1761843436312.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 16:57:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910586#M106964</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2025-10-30T16:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910597#M106968</link>
      <description>&lt;P&gt;Really the main reason is because I found it simpler to loop through the different levels of my variable and build each tab window that way, then append. Since for each level I am performing calculations for tables, building a graph with graph builder, extracting qq plots from the Dist platform, extracting the studentized residual plot from the fit model platform, etc.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 17:28:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910597#M106968</guid>
      <dc:creator>rcast15</dc:creator>
      <dc:date>2025-10-30T17:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910598#M106969</link>
      <description>&lt;P&gt;Thank you both for your input, the code provided all works well. I should add that I am building a fairly complex add-in that pulls from a lot of different platforms and creates some novel output as well. What I really wanted was to ensure my plots and tables that are normally linked to my data table to remain that way. I also wanted every single tab to look the exact same, so looping seemed like an easy fix.&lt;/P&gt;
&lt;P&gt;Do you think the best way to go about this is to just use the By option in all the platforms I am using and then loop thru the levels of my variable calling each component using the various paths and appending those where I want them?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 17:34:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910598#M106969</guid>
      <dc:creator>rcast15</dc:creator>
      <dc:date>2025-10-30T17:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting the same output for all levels of a categorical variable</title>
      <link>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910599#M106970</link>
      <description>&lt;P&gt;If you append them like Jim did demonstrate, they will end up loosing the interactivity. Subset/Where do both work quite well but there are cases where you are not able to utilize Where that easily such as creation of summary tables (it uses local data filter instead of simple Where). And with subsets you can potentially end up with a lot of data tables you might have to deal with as they might not close as you expect them to (when closing the main table). Sometimes it might also be worth considering to use Local Data Filter as you use one filter for multiple platforms with Data Filter Context Box.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Oct 2025 17:53:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Scripting-the-same-output-for-all-levels-of-a-categorical/m-p/910599#M106970</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-10-30T17:53:39Z</dc:date>
    </item>
  </channel>
</rss>

