<?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: Deleting multiple columns based on strings in their name in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257557#M50614</link>
    <description>&lt;P&gt;Jim,&lt;BR /&gt;Sorry, for misunderstanding. But most of the things that I search is not well very described or just briefly explained in the jsl pdf. Especially recursive scripting (if-else, for loop) when you want to do complex things they are not included in the manual. It's very hard to track the errors as well. I did not until you say to check the 'log'.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For example, there is no explanation about creating a new data table or how to assign a new data table.&lt;/P&gt;
&lt;P&gt;What I was thinking as straight forward like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt_new &amp;lt;&amp;lt; Data Table( col_names );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should create a new data table but I learned that it is not straight forward in jmp. We need to ask or practice about the syntax that's I'm doing.&lt;BR /&gt;Thanks a lot!&lt;/P&gt;</description>
    <pubDate>Mon, 13 Apr 2020 09:03:38 GMT</pubDate>
    <dc:creator>joshua</dc:creator>
    <dc:date>2020-04-13T09:03:38Z</dc:date>
    <item>
      <title>Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257524#M50603</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to delete multiple columns based the strings they contain but sometimes I want to keep some others even if they don't contain those strings.&lt;/P&gt;
&lt;P&gt;So by following this post's solution&amp;nbsp;&lt;LI-MESSAGE title="Deleting multiple columns based on column name" uid="47227" url="https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-column-name/m-p/47227#U47227" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/Hollywood Movies.jmp" );
col_names =  dt &amp;lt;&amp;lt; Get Column Names( String );

For( i = N Items( col_names ), i &amp;gt; 0, i--,
	If(
		Not(
			Contains( col_names[i], "Gross")  | contains(col_names[i], "Genre"   ) | col_names[i] == "theme"),

	Remove From( col_names, i)
	)
);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, what I want to have is remove anything not contains with "Gross" or "Genre" but if the column name is == "theme" don't remove it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems it does not work for now ! Why?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 504px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22957i461F71676B335F9C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second bullet to this question&lt;/P&gt;
&lt;P&gt;How can I see col_names as a data table so I can know what is the output without hovering on the col_names. Because sometimes I have a long list of col names and hovering is not efficient to see what is in that column list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:26:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257524#M50603</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2023-06-09T23:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257531#M50605</link>
      <description>&lt;P&gt;From the JSL you provided, you have left out the most critical statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; delete columns( col_names );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the line that actually does the deletions.&amp;nbsp; However, in this sample case, it has an additional issue.&amp;nbsp; The final list of columns&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;{"Genre", "Domestic Gross", "Foreign Gross", "World Gross", "Opening Wknd Gross"}&lt;/PRE&gt;
&lt;P&gt;has the column "World Gross" in it, which is used in the calculation of column "Profitability".&amp;nbsp; When the "delete columns" message is processed it detects the issue and displays in the log&lt;/P&gt;
&lt;PRE&gt;Cannot delete the selected columns while some are referenced by the formulas of remaining columns.
Removing a formula leaves the data unchanged. Removing references replaces each reference with an empty value. These effects are permanent and cannot be undone.&lt;/PRE&gt;
&lt;P&gt;If you delete the formula from the "Profitability" column, it will convert the values to static values,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt:Profitability &amp;lt;&amp;lt; delete formula;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then the "delete columns" will work properly.&lt;/P&gt;
&lt;P&gt;Concerning your issue about hovering over a variable to see it's value, and wanting to create a data table to be able to see the values, there is a much simpler way to do that.&amp;nbsp; Rather than hovering over the "col_names" variable, what you need to do, is to highlight it, and then right click and select "Run Script".&amp;nbsp; By rule, if anything in a JMP script is highlighted, the "Run Script" will only run the highlighted lines/statements/variables.&amp;nbsp; The results will be displayed in the log.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 19:03:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257531#M50605</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-04-12T19:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257535#M50606</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer. Ok I see about what you saying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say we don't care about the formulas. Let's delete all of the formula connections and remove the columns that I wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want to create (and see ) those deleted columns as a datatable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by following your suggestion&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/Hollywood Movies.jmp" );
col_names =  dt &amp;lt;&amp;lt; Get Column Names( String );


dt:Profitability &amp;lt;&amp;lt; delete formula;

For( i = N Items( col_names ), i &amp;gt; 0, i--,
	If(
		Not(
			Contains( col_names[i], "Gross")  | contains(col_names[i], "Genre"   ) | col_names[i] == "theme"),

	Remove From( col_names, i)
	)
);

deleted_columns = delete columns( col_names );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;this does not create still what I need :(&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 19:23:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257535#M50606</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-04-12T19:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257543#M50608</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/Hollywood Movies.jmp" );
col_names =  dt &amp;lt;&amp;lt; Get Column Names( String );


dt:Profitability &amp;lt;&amp;lt; delete formula;

For( i = N Items( col_names ), i &amp;gt; 0, i--,
	If(
		Not(
			Contains( col_names[i], "Gross")  | contains(col_names[i], "Genre"   ) | col_names[i] == "theme"),

	Remove From( col_names, i)
	)
);
// At this point in the script, you have a data table 
// with all of the original columns(Profitability is now a static column)
// And you have a JSL List called "col_names", which is stored in memory
// so you can do anythin you want given this
// You could just write the contents of the list to the log.  Remember, the 
// list "col_names", only contains the names of the columns, it does not 
// contain the whole column(name, properties and data)
Print( col_names );
// or
Write( col_names );
// or
Show( col_names );
// That will give you the list of columns that are going to be deleted
// or before you want to see the columns in their entirety you can create
// a new data table with just those columns

newdt = dt &amp;lt;&amp;lt; subset( all rows, columns( col_names ) );

// The statement below, is a perfectly valid statement, however, it will
// not work the way you think it will.  The end result of this statement
// is to create a new list of column names. 
// {"Genre", "Domestic Gross", "Foreign Gross", "World Gross", "Opening Wknd Gross"}
deleted_columns = delete columns( col_names );

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Apr 2020 19:50:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257543#M50608</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-04-12T19:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257554#M50612</link>
      <description>&lt;P&gt;why&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col_names[i] == "theme"&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;is not still working ?&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 576px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22959i6089651F3DC22D6F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 23:59:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257554#M50612</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-04-12T23:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257555#M50613</link>
      <description>&lt;P&gt;If you print out the value of "col_names" right after it is created, it shows all of the columns in the data table&lt;/P&gt;
&lt;PRE&gt;{"Movie Name", "Lead Studio Name", "Rotten Tomatoes Score", "Audience Score",
"Theme", "Genre", "Theaters Opening Wknd", "BOA Opening Wknd", "Domestic Gross",
"Foreign Gross", "World Gross", "Production Budget", "Profitability",
"Opening Wknd Gross"}&lt;/PRE&gt;
&lt;P&gt;If you look closely, you will see there is not an entry with the value "theme". &amp;nbsp; There is an entry with the value "Theme".&amp;nbsp; You are comparing values in character strings, and you have to properly match uppercase and lowercase.&lt;/P&gt;
&lt;P&gt;I strongly suggest that you read the Scripting Guide!&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Help==&amp;gt;JMP Documentation Library &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Scripting Guide&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 00:37:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257555#M50613</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-04-13T00:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257557#M50614</link>
      <description>&lt;P&gt;Jim,&lt;BR /&gt;Sorry, for misunderstanding. But most of the things that I search is not well very described or just briefly explained in the jsl pdf. Especially recursive scripting (if-else, for loop) when you want to do complex things they are not included in the manual. It's very hard to track the errors as well. I did not until you say to check the 'log'.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For example, there is no explanation about creating a new data table or how to assign a new data table.&lt;/P&gt;
&lt;P&gt;What I was thinking as straight forward like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt_new &amp;lt;&amp;lt; Data Table( col_names );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;should create a new data table but I learned that it is not straight forward in jmp. We need to ask or practice about the syntax that's I'm doing.&lt;BR /&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 09:03:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257557#M50614</guid>
      <dc:creator>joshua</dc:creator>
      <dc:date>2020-04-13T09:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting multiple columns based on strings in their name</title>
      <link>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257597#M50623</link>
      <description>&lt;P&gt;Your confusion about the data table is something I have seen before.&amp;nbsp; What is different about JMP and it's data tables, is that a data table needs to be thought of as a base element.&amp;nbsp; Much of the time, one will see a line of JSL such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/big class.jmp");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In some languages, dt would be the data table.&amp;nbsp; This is not the case.&amp;nbsp; The above statement only assigns a pointer to the data table "Big Class".&amp;nbsp; And if you hover over the variable dt you will see&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;data table( "Big Class" )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as it's value.&lt;/P&gt;
&lt;P&gt;Therefore, if I run the statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;xyz = dt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not get a new instance of the data table Big Class, as I would in some languages, instead, all I get is variable called xyz which is a pointer to the same data table called Big Class.&lt;/P&gt;
&lt;P&gt;To create a new copy (it is not a new instance, because once created it typically is a totally independent new data table)&amp;nbsp; one uses one of the Table platforms to complete the task&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt2 = dt &amp;lt;&amp;lt; subset( all rows, all columns);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above command creates a new data table and will set variable dt2 as a pointer to the new table.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 06:03:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Deleting-multiple-columns-based-on-strings-in-their-name/m-p/257597#M50623</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-04-13T06:03:49Z</dc:date>
    </item>
  </channel>
</rss>

