<?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 JSL : Get a list of columns containing a specific value in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409090#M65886</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to list all columns containing a specific value in any of their rows and get the listing of those columns.&lt;/P&gt;&lt;P&gt;I start by listing all character columns in a list and loop in it to check if a specific value is contained in each of the columns. Here is the code I used. Any idea how to help me? Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; get column names( character );
nc = N Items( col );
colList = {};

For( i = 1, i &amp;lt;= nc, i++,
	If(Contains (as column(dt,col[i]) ,"null"),
	Insert Into( colList, col[i] ))
);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 19:54:30 GMT</pubDate>
    <dc:creator>Starwatcher</dc:creator>
    <dc:date>2023-06-09T19:54:30Z</dc:date>
    <item>
      <title>JSL : Get a list of columns containing a specific value</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409090#M65886</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I would like to list all columns containing a specific value in any of their rows and get the listing of those columns.&lt;/P&gt;&lt;P&gt;I start by listing all character columns in a list and loop in it to check if a specific value is contained in each of the columns. Here is the code I used. Any idea how to help me? Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = dt &amp;lt;&amp;lt; get column names( character );
nc = N Items( col );
colList = {};

For( i = 1, i &amp;lt;= nc, i++,
	If(Contains (as column(dt,col[i]) ,"null"),
	Insert Into( colList, col[i] ))
);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:54:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409090#M65886</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2023-06-09T19:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: JSL : Get a list of columns containing a specific value</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409111#M65889</link>
      <description>&lt;P&gt;I think this might do what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = current data table();
col = dt &amp;lt;&amp;lt; get column names( character );
nc = N Items( col );
colList = {};

For( i = 1, i &amp;lt;= nc, i++,
	If( N Rows( dt &amp;lt;&amp;lt; get rows where( As Column( dt, col[i] ) == "null" ) ) &amp;gt; 0,
		Insert Into( colList, col[i] )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 14:11:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409111#M65889</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-08-12T14:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: JSL : Get a list of columns containing a specific value</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409171#M65892</link>
      <description>&lt;P&gt;Couple of more ways below. I would suggest using txnelson's solution as it is easier to understand.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(5),
	New Column("Column 1", Character, "Nominal", Set Values({"null", "a", "s", "d", "vb"})),
	New Column("Column 2", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"})),
	New Column("Column 3", Character, "Nominal", Set Values({"a", "a", "a", "a", "a"})),
	New Column("Column 4", Character, "Nominal", Set Values({"null", "a", "a", "a", "a"})),
	New Column("Column 5", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 5])),
	New Column("Column 6", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4, 5])),
	New Column("Column 7", Character, "Nominal", Set Values({"a", "a", "a", "null", "a"}))
);

//using Loc and matrix subscripting
char_col_names = dt &amp;lt;&amp;lt; Get Column Names(character);
null_cols = {};
For(i = 1, i &amp;lt;= N Items(char_col_names), i++,
	If(N Items(Loc(dt[0, char(char_col_names[i])], "null")) &amp;gt; 0,
		Insert Into(null_cols, char_col_names[i]);
	);
);
Show(null_cols);

//Using list flattening and loc with "2d" matrix

//List flattening function from here https://community.jmp.com/t5/Discussions/JSL-Question-How-to-flatten-quot-a-list-of-lists/td-p/56535
rec = Function({ll},
	{i},
	If(Is List(ll),
		For(i = 1, i &amp;lt;= N Items(ll), i++,
			If(!Is List(ll[i]),
				Insert Into(llnew, ll[i]), //else
				rec(ll[i])
			)
		)
	)
);
flatten = Function({ulist},
	{llnew = {}},
	rec(ulist);
	llnew;
);

col_names = dt &amp;lt;&amp;lt; Get Column Names();
//https://community.jmp.com/t5/JSL-Cookbook/Using-Loc-with-a-2D-Matrix/ta-p/195207
null_loc = Loc(flatten(dt[0, col_names ]), "null") - 1;
column_loc = Mod(null_loc, N Items(col_names )) + 1;
Show(col_names[column_loc]);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you run into "issues" with the speed of the script you can see if this topic could help &lt;A href="https://community.jmp.com/t5/Discussions/Should-you-Loop-through-a-data-table-or-use-Recode-or-use-Get/m-p/381444/highlight/true#M63199" target="_blank" rel="noopener"&gt;Should you Loop through a data table or use Recode or use Get&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 15:11:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409171#M65892</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-08-12T15:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: JSL : Get a list of columns containing a specific value</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409368#M65914</link>
      <description>&lt;P&gt;Thank you, this works like a charm!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 07:44:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409368#M65914</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2021-08-13T07:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSL : Get a list of columns containing a specific value</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409369#M65915</link>
      <description>&lt;P&gt;Many solutions, thank you for these insights!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 08:01:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Get-a-list-of-columns-containing-a-specific-value/m-p/409369#M65915</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2021-08-13T08:01:08Z</dc:date>
    </item>
  </channel>
</rss>

