<?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: Choose output of a new column based on name of the column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689836#M87582</link>
    <description>Hi jthi, I am using version 15!</description>
    <pubDate>Tue, 24 Oct 2023 05:53:20 GMT</pubDate>
    <dc:creator>Yula</dc:creator>
    <dc:date>2023-10-24T05:53:20Z</dc:date>
    <item>
      <title>Choose output of a new column based on name of the column</title>
      <link>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689792#M87578</link>
      <description>I have column names with student names and the class/es that they’ve attended:&lt;BR /&gt;&lt;BR /&gt;Name, Class A1, Class A2, Class A3, Class A, Class B&lt;BR /&gt;&lt;BR /&gt;Where not every Class column has an input. On my script, how can I create a new column where it will only choose the output where:&lt;BR /&gt;&lt;BR /&gt;If a student attended all “A” Classes, the output is from column Class A.&lt;BR /&gt;&lt;BR /&gt;If a student attended Class A1 through A2 or A3, the output is from the class with the highest number (column Class A is empty).&lt;BR /&gt;&lt;BR /&gt;If a student attended Class B, this student did not attend any of the “A” Classes (all empty) and so the output is from Class B.&lt;BR /&gt;&lt;BR /&gt;For now I was able to run a for loop to compile all the column names in a list. However, I’m not sure how to compare all the column names to this logic. I’m relatively new to writing scripts on JMP so any help is appreciated!</description>
      <pubDate>Tue, 24 Oct 2023 04:01:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689792#M87578</guid>
      <dc:creator>Yula</dc:creator>
      <dc:date>2023-10-24T04:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Choose output of a new column based on name of the column</title>
      <link>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689816#M87580</link>
      <description>&lt;P&gt;Which JMP version you are using (it changes which type of looping can be used)?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 05:01:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689816#M87580</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-24T05:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Choose output of a new column based on name of the column</title>
      <link>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689836#M87582</link>
      <description>Hi jthi, I am using version 15!</description>
      <pubDate>Tue, 24 Oct 2023 05:53:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689836#M87582</guid>
      <dc:creator>Yula</dc:creator>
      <dc:date>2023-10-24T05:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Choose output of a new column based on name of the column</title>
      <link>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689842#M87583</link>
      <description>&lt;P&gt;This solution looks complicated but the idea is: get list of all class columns and then use data table subscripting WITH that list and get maximum index of found values (so this assumes that the columns are ordered)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	Compress File When Saved(1),
	New Column("n", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., .])),
	New Column("Class A1", Character, "Nominal", Set Values({"A1", "", "A1", ""})),
	New Column("Class A2", Character, "Nominal", Set Values({"", "A2", "A2", ""})),
	New Column("Class A", Character, "Nominal", Set Values({"", "", "", "A"})),
	New Column("Class B", Character, "Nominal", Set Values({"", "", "", "", "B"}))
);
col_list = dt &amp;lt;&amp;lt; Get Column Names("String");

class_cols = {};
For(i = 1, i &amp;lt;= N Items(col_list), i++,
	col_name = col_list[i];
	If(Starts With(col_name, "Class "),
		Insert Into(class_cols, col_name);
	);
);

dt &amp;lt;&amp;lt; New Column("CLASS GROUP", Character, Nominal, &amp;lt;&amp;lt; Set Each Value(
	valcol = Max(Loc(Matrix(!IsMissing(dt[Row(), class_cols])))) + 1;
	dt[Row(), valcol];
));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1698127358278.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57918i18DA7C27639A32E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1698127358278.png" alt="jthi_0-1698127358278.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 06:03:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Choose-output-of-a-new-column-based-on-name-of-the-column/m-p/689842#M87583</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-24T06:03:43Z</dc:date>
    </item>
  </channel>
</rss>

