<?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 check if column exists? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572468#M78167</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to create a new column and before doing so:&lt;/P&gt;&lt;P&gt;ask the data table if the column already exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a "best" way such that the code can be shared with other colleagues in the company?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Check column name if existing" uid="311971" url="https://community.jmp.com/t5/Discussions/Check-column-name-if-existing/m-p/311971#U311971" 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;&lt;LI-MESSAGE title="How to check if list of columns exist and report those that are missing using a pop-up window?" uid="515287" url="https://community.jmp.com/t5/Discussions/How-to-check-if-list-of-columns-exist-and-report-those-that-are/m-p/515287#U515287" 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;&lt;LI-MESSAGE title="Determining if a column exists" uid="6268" url="https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6268#U6268" 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;&lt;LI-MESSAGE title="Create a new Row() column only if it does not exist" uid="309172" url="https://community.jmp.com/t5/Discussions/Create-a-new-Row-column-only-if-it-does-not-exist/m-p/309172#U309172" 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;&lt;LI-MESSAGE title="Validate column name exists before graphing" uid="5088" url="https://community.jmp.com/t5/Discussions/Validate-column-name-exists-before-graphing/m-p/5088#U5088" 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;</description>
    <pubDate>Wed, 28 Jun 2023 16:32:59 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-06-28T16:32:59Z</dc:date>
    <item>
      <title>check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572468#M78167</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to create a new column and before doing so:&lt;/P&gt;&lt;P&gt;ask the data table if the column already exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a "best" way such that the code can be shared with other colleagues in the company?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Check column name if existing" uid="311971" url="https://community.jmp.com/t5/Discussions/Check-column-name-if-existing/m-p/311971#U311971" 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;&lt;LI-MESSAGE title="How to check if list of columns exist and report those that are missing using a pop-up window?" uid="515287" url="https://community.jmp.com/t5/Discussions/How-to-check-if-list-of-columns-exist-and-report-those-that-are/m-p/515287#U515287" 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;&lt;LI-MESSAGE title="Determining if a column exists" uid="6268" url="https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6268#U6268" 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;&lt;LI-MESSAGE title="Create a new Row() column only if it does not exist" uid="309172" url="https://community.jmp.com/t5/Discussions/Create-a-new-Row-column-only-if-it-does-not-exist/m-p/309172#U309172" 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;&lt;LI-MESSAGE title="Validate column name exists before graphing" uid="5088" url="https://community.jmp.com/t5/Discussions/Validate-column-name-exists-before-graphing/m-p/5088#U5088" 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;</description>
      <pubDate>Wed, 28 Jun 2023 16:32:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572468#M78167</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-06-28T16:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572549#M78175</link>
      <description>&lt;P&gt;Seems like each of those solutions would work. The most robust would likely be the 2nd link, but it also has the most lines of code.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 16:05:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572549#M78175</guid>
      <dc:creator>Jed_Campbell</dc:creator>
      <dc:date>2022-11-23T16:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572558#M78176</link>
      <description>&lt;P&gt;my farorite: Jim's idea to just &lt;STRONG&gt;ask&lt;/STRONG&gt;&amp;nbsp;the data table for the column and check if the data table complains.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But even this approach relies on the fact that the spelling of the column name while asking fits to the actual name.&lt;/P&gt;&lt;P&gt;e.g. it doesn't find "a g e" if you ask for "age".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the new column &lt;STRONG&gt;:age&lt;/STRONG&gt; would cut all links between &lt;STRONG&gt;:age&lt;/STRONG&gt; and the existing column &lt;STRONG&gt;:a g e&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This could lead to such collateral damages:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt:age &amp;lt;&amp;lt; set name("a g e");

Show(dt: age [5]); // points to the existing column
	
Try(:is there a = column(dt,"age"), "answer: no");

new Column("age");
Show(dt: age[5])&amp;nbsp;//&amp;nbsp;points&amp;nbsp;to&amp;nbsp;the&amp;nbsp;new&amp;nbsp;column&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2022 16:23:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572558#M78176</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2022-11-23T16:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572570#M78177</link>
      <description>&lt;P&gt;The most reliable method that I have found, is to ask for the name of the variable, &amp;lt;&amp;lt; get name&lt;/P&gt;
&lt;P&gt;It honors blanks, etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dt=current data table();
dt:age &amp;lt;&amp;lt; set name("a g e");
tn="age";
r=try(column(dt,tn)&amp;lt;&amp;lt;get name,"");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2022 16:44:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/572570#M78177</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-11-23T16:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573006#M78188</link>
      <description>&lt;P&gt;Actually, no &lt;STRONG&gt;&lt;EM&gt;need&lt;/EM&gt;&lt;/STRONG&gt; to ask for the name, right?&lt;BR /&gt;The trick lies in the&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Try(column(dt,"age"), &lt;EM&gt;check for failure&lt;/EM&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Try to get the column - and check if it fails.&lt;/P&gt;&lt;P&gt;Not only ultra-short - but also an excellent choice regarding &lt;STRONG&gt;robustness&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;:)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And - as the icing on the cake - ask the column for it's name:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;r=try(column(dt,tn)&amp;lt;&amp;lt;get name,"");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A nice trick to get a well-defined return type for existing and non-existing columns. Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;:)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 12:49:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573006#M78188</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-01-17T12:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573017#M78191</link>
      <description>&lt;P&gt;I believe that you're just supposed to use the &lt;CODE class=" language-jsl"&gt;As Name()&lt;/CODE&gt; function for this.&amp;nbsp; It makes these checks easy and you don't have to worry about spacing / capitalizations:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt:age &amp;lt;&amp;lt; set name("a g e");

Show( Contains( dt &amp;lt;&amp;lt; Get Column Names, As Name( "a ge" ) ) );

Show( Contains( dt &amp;lt;&amp;lt; Get Column Names, As Name( "S   eX" ) ) );

name to check = "N a ME";
Show( Contains( dt &amp;lt;&amp;lt; Get Column Names, As Name( name to check ) ) )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2022 20:43:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573017#M78191</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-11-23T20:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573023#M78192</link>
      <description>&lt;P&gt;Ah nice :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To prevent users in general from forgetting the&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;As Name&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in their code, how about adding a function to the data table object to ask if the column exists:&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="data table : message column exists(colname)?" uid="573018" url="https://community.jmp.com/t5/JMP-Wish-List/data-table-message-column-exists-colname/m-p/573018#U573018" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;delivered with JMP18:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1719673103395.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/65728iEC25FFD7B4E5CCDA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1719673103395.png" alt="hogi_0-1719673103395.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>Sat, 29 Jun 2024 14:58:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573023#M78192</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-06-29T14:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: check if column exists?</title>
      <link>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573152#M78209</link>
      <description>&lt;P&gt;some more insights:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;cool!&lt;BR /&gt;Didn't know/notice that the comparison works&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt; the &lt;STRONG&gt;string&lt;/STRONG&gt;&amp;nbsp;option of&amp;nbsp;&lt;STRONG&gt;get column names&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;as robust as&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;'s&amp;nbsp; &amp;nbsp;&lt;CODE class=" language-jsl"&gt;try(column(dt,"Age"))&lt;BR /&gt;&lt;/CODE&gt;&lt;STRONG&gt;&lt;SPAN&gt;age ~ Age&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;just use &lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;string&lt;/FONT&gt;&lt;SPAN&gt; as an argument for Get Column Names if you want to differentiate between&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;age&amp;nbsp; &lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt; Age&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");


Show(dt &amp;lt;&amp;lt; Get Column Names(String));
Show( Contains( dt &amp;lt;&amp;lt; Get Column Names(String), As Name( "Age") ) ); // -&amp;gt; nope

Show(dt &amp;lt;&amp;lt; Get Column Names);
Show( Contains( dt &amp;lt;&amp;lt; Get Column Names, As Name( "Age") ) ); // found !
Show(r=try(column(dt,"Age")&amp;lt;&amp;lt;get name,"")); // found :)

Show(dt:Age[1]);
dt &amp;lt;&amp;lt; New Column("Age", Numeric, Ordinal);
dt:Age[1] = 0;
Show(dt:Age[1]);


wait(1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 11:46:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/check-if-column-exists/m-p/573152#M78209</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2022-11-24T11:46:08Z</dc:date>
    </item>
  </channel>
</rss>

