<?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 Creating column subset based on list which may contain non-existent columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/369950#M61968</link>
    <description>&lt;P&gt;Hi Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read through a prior discussion related to this topic but did not find all the answers.&lt;/P&gt;&lt;P&gt;I would like to know how to create a column subset based on a given list of columns. I know that you can easily do this when the columns in the given list exist in the datatable you would like to subset.&lt;/P&gt;&lt;P&gt;What I want to know is how do you make the script robust so that it does not give the error that "Column not found in access or evaluation of 'Bad Argument' in the case that a given column in the list does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in my script below, I want to still be able to create a subset of "Big Class.jmp" with columns, name, age and height because they exist but my script breaks down as it is because I have a non-existent column in the given list called, none.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried putting Try() around the code but no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cols_of_interest = {:name, :age, :height, :none};
show(cols_of_interest);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
big_class_cols = dt &amp;lt;&amp;lt; Get Column Names();
show(big_class_cols);

subDt1 = dt &amp;lt;&amp;lt; Subset(
	Columns( cols_of_interest ),
	Output Table Name( "Big Class 2" )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;"&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Simon&lt;/P&gt;</description>
    <pubDate>Sat, 10 Jun 2023 23:27:33 GMT</pubDate>
    <dc:creator>simon_2</dc:creator>
    <dc:date>2023-06-10T23:27:33Z</dc:date>
    <item>
      <title>Creating column subset based on list which may contain non-existent columns</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/369950#M61968</link>
      <description>&lt;P&gt;Hi Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read through a prior discussion related to this topic but did not find all the answers.&lt;/P&gt;&lt;P&gt;I would like to know how to create a column subset based on a given list of columns. I know that you can easily do this when the columns in the given list exist in the datatable you would like to subset.&lt;/P&gt;&lt;P&gt;What I want to know is how do you make the script robust so that it does not give the error that "Column not found in access or evaluation of 'Bad Argument' in the case that a given column in the list does not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in my script below, I want to still be able to create a subset of "Big Class.jmp" with columns, name, age and height because they exist but my script breaks down as it is because I have a non-existent column in the given list called, none.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried putting Try() around the code but no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cols_of_interest = {:name, :age, :height, :none};
show(cols_of_interest);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
big_class_cols = dt &amp;lt;&amp;lt; Get Column Names();
show(big_class_cols);

subDt1 = dt &amp;lt;&amp;lt; Subset(
	Columns( cols_of_interest ),
	Output Table Name( "Big Class 2" )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;"&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Simon&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:27:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/369950#M61968</guid>
      <dc:creator>simon_2</dc:creator>
      <dc:date>2023-06-10T23:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating column subset based on list which may contain non-existent columns</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/369953#M61969</link>
      <description>&lt;P&gt;Here is a simple way to handle this.&amp;nbsp; It simply checks to see if each column&amp;nbsp; from the cols_of_interest list exists in the data table, and if not, it removes it from the cols_of_interest list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

cols_of_interest = {:name, :age, :height, :none};
show(cols_of_interest);

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

For(i=nitems(cols_of_interest), i&amp;gt;=1, i--,
	if(try(column(dt,char(cols_of_interest[i]))&amp;lt;&amp;lt;get name,"") == "",
		remove from(cols_of_interest,i,1);
));

subDt1 = dt &amp;lt;&amp;lt; Subset(
	Columns( cols_of_interest ),
	Output Table Name( "Big Class 2" )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Mar 2021 04:57:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/369953#M61969</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-20T04:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating column subset based on list which may contain non-existent columns</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/370020#M61979</link>
      <description>&lt;P&gt;Here's a way to use &amp;lt;&amp;lt;intersect to determine the columns that exist in both lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
cols_of_interest = {name, age, height, none}; //names without scoping colon

AA1 = Associative Array( dt &amp;lt;&amp;lt; Get Column Names() );
AA2 = Associative Array( cols_of_interest );
cols = AA2 &amp;lt;&amp;lt; intersect( AA1 ) &amp;lt;&amp;lt; get keys;

subDt1 = dt &amp;lt;&amp;lt; Subset( Columns( cols ), Output Table Name( "Big Class 2" ) );
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Mar 2021 16:57:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/370020#M61979</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-03-20T16:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating column subset based on list which may contain non-existent columns</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/370070#M61986</link>
      <description>Very elegant solution. It works great.&lt;BR /&gt;Thanks Jim!</description>
      <pubDate>Sun, 21 Mar 2021 01:41:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-column-subset-based-on-list-which-may-contain-non/m-p/370070#M61986</guid>
      <dc:creator>simon_2</dc:creator>
      <dc:date>2021-03-21T01:41:37Z</dc:date>
    </item>
  </channel>
</rss>

