<?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: Determining if a column exists in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6276#M6275</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PMroz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me start by confirming that the code you wrote worked for me as well, and the explaination I wrote is not consistent with JMP 9 or 10 behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After reading your reply, I also tried several different combinations of contains, and if statements with lists, string, and numbers in JMP 9 and 10. Although my attempts were not exhaustive, all of my results are consistent with yours. Initially, when I read your first post I recalled some troubleshooting that I had perform years prior where I had adopted the the use of contains()&amp;gt;0. I am unable to recreate the scenario; however, I did find the following information in the JMP scripting guide. It details using contains with &amp;gt;0, which may be appropriate for their example, but does not explicitly state that it is or is not required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Page 136 of the JMP scripting guide version 10:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;"To assess whether an item is in a list, use &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Loc() &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;and &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Contains() &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;with &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;&amp;gt;0&lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;. A returned value of zero&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;means that the item is not in the list. A returned value of 1 means that the item is in the list at least once."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;"Find out if the number &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;5 &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;exists in the &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;numList:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;NRow(Loc(numList, 5)) &amp;gt;0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-size: 9pt; font-family: LucidaSansTypewriter,Italic;"&gt;0&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Contains(numList, 5) &amp;gt;0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-size: 9pt; font-family: LucidaSansTypewriter,Italic;"&gt;0"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 24 Feb 2013 13:37:47 GMT</pubDate>
    <dc:creator>wiebepo</dc:creator>
    <dc:date>2013-02-24T13:37:47Z</dc:date>
    <item>
      <title>Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6268#M6267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a JMP script that creates a new column with a formula in it. I'm trying to find out how to detect if the column already exists so that I can skip creating it, and avoid generating extra columns. I'm sure it's there, but I'm not finding it in the literature that I have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 17:48:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6268#M6267</guid>
      <dc:creator>mwechtal</dc:creator>
      <dc:date>2013-02-06T17:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6269#M6268</link>
      <description>&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = open("$sample_data\Big Class.jmp");
 
col_name_list = dt &amp;lt;&amp;lt; get column names(string);
 
new_column = "BMI";
 
// English BMI Formula
// BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
 
if (!contains(col_name_list, new_column),
      dt &amp;lt;&amp;lt;New Column("BMI", numeric, continuous,
            formula(703 * :weight / :height / :height)
      );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 18:25:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6269#M6268</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-06-25T18:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6270#M6269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, that works just fine for me. I was expecting to find a function to check for existance, but this works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 19:13:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6270#M6269</guid>
      <dc:creator>mwechtal</dc:creator>
      <dc:date>2013-02-06T19:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6271#M6270</link>
      <description>&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black;"&gt;I am not certain if this is true in all recent versions of JMP. I make this comment only to highlight an opportunity to improve the robustness of the code. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: 'Courier New'; color: black;"&gt;'Contains' returns the position of the item, which is fine to use in an 'if' statement, since zero will be interpreted as false and a positive value will be interpreted true. When preceding a contains with a not '!', the condition works when the item is not present or when present as the first item; however, when the item isn't first ( a value greater than 1 ), the not '!' can fail to convert the condition to false. This can be avoided by using a comparison '&amp;gt;0' with the 'contains'. See below for syntax.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data\Big Class.jmp" );
 
col_name_list = dt &amp;lt;&amp;lt; get column names( string );
 
new_column = "BMI";
 
// English BMI Formula
// BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
 
If( !(Contains( col_name_list, new_column ) &amp;gt; 0),
	dt &amp;lt;&amp;lt; New Column( "BMI", numeric, continuous, formula( 703 * :weight / :height / :height ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 15:41:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6271#M6270</guid>
      <dc:creator>wiebepo</dc:creator>
      <dc:date>2018-05-02T15:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6272#M6271</link>
      <description>&lt;P&gt;There is no single function that I am aware of. But &lt;EM&gt;Is missing()&lt;/EM&gt; in combination with &lt;EM&gt;Is Scriptable()&lt;/EM&gt; can do the trick.&lt;/P&gt;
&lt;P&gt;The column also need to be enclosed by a Try() statement to avoid the script from stopping if the column would not exist.&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" );
 
new_column = "BMI";
 
If( Is Missing( Is Scriptable( Try( Column( new_column ) ) ) ),
	dt &amp;lt;&amp;lt; New Column( new_column, numeric, continuous, formula( 703 * :weight / :height / :height ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #a70096;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 15:41:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6272#M6271</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2018-05-02T15:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6273#M6272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's very handy to know. I'll have to watch out for that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 15:58:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6273#M6272</guid>
      <dc:creator>mwechtal</dc:creator>
      <dc:date>2013-02-13T15:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6274#M6273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also handy to know. I'm always glad to have another tool to add to the toolbox.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 16:01:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6274#M6273</guid>
      <dc:creator>mwechtal</dc:creator>
      <dc:date>2013-02-13T16:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6275#M6274</link>
      <description>&lt;P&gt;Hello wiebepo,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried different combinations and negating a positive integer, no matter how large, results in a 0.&amp;nbsp; So my code will work (in JMP 9 and 10).&amp;nbsp; Having said that I appreciate the heads up - this approach might not work in all languages.&amp;nbsp; It certainly bears further testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;b = 2000000000000;
!b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log shows:&lt;/P&gt;
&lt;P&gt;&lt;STRONG style="color: black; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;PMroz&lt;/P&gt;</description>
      <pubDate>Wed, 02 May 2018 15:42:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6275#M6274</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-05-02T15:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6276#M6275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PMroz,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me start by confirming that the code you wrote worked for me as well, and the explaination I wrote is not consistent with JMP 9 or 10 behavior.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After reading your reply, I also tried several different combinations of contains, and if statements with lists, string, and numbers in JMP 9 and 10. Although my attempts were not exhaustive, all of my results are consistent with yours. Initially, when I read your first post I recalled some troubleshooting that I had perform years prior where I had adopted the the use of contains()&amp;gt;0. I am unable to recreate the scenario; however, I did find the following information in the JMP scripting guide. It details using contains with &amp;gt;0, which may be appropriate for their example, but does not explicitly state that it is or is not required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Page 136 of the JMP scripting guide version 10:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;"To assess whether an item is in a list, use &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Loc() &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;and &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Contains() &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;with &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;&amp;gt;0&lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;. A returned value of zero&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;means that the item is not in the list. A returned value of 1 means that the item is in the list at least once."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;"Find out if the number &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;5 &lt;/SPAN&gt;&lt;SPAN style="font-family: AGaramond-Regular; font-size: 10pt;"&gt;exists in the &lt;/SPAN&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;numList:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;NRow(Loc(numList, 5)) &amp;gt;0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-size: 9pt; font-family: LucidaSansTypewriter,Italic;"&gt;0&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: LucidaSansTypewriter; font-size: 9pt;"&gt;Contains(numList, 5) &amp;gt;0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-size: 9pt; font-family: LucidaSansTypewriter,Italic;"&gt;0"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Feb 2013 13:37:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/6276#M6275</guid>
      <dc:creator>wiebepo</dc:creator>
      <dc:date>2013-02-24T13:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/55531#M31399</link>
      <description>Thanks ms!&lt;BR /&gt;Only your example worked for me, because the other solution is case sensitive. I had to use yours, since I could not be sure that the case of my string characters are correct.</description>
      <pubDate>Thu, 26 Apr 2018 11:24:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/55531#M31399</guid>
      <dc:creator>Rob</dc:creator>
      <dc:date>2018-04-26T11:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Determining if a column exists</title>
      <link>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/55586#M31410</link>
      <description>&lt;P&gt;Here's a version of my logic that's case-insensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = open("$sample_data\Big Class.jmp");
col_name_list = dt &amp;lt;&amp;lt; get column names(string);
// Convert all column names to uppercase for case-insensitive search
for (i = 1, i &amp;lt;= nitems(col_name_list), i++,
	col_name_list[i] = uppercase(col_name_list[i]);
);
new_column = "BMI";
// English BMI Formula BMI = ( Weight in Pounds / ( Height in inches^2 ) ) x 703
if (!contains(col_name_list, uppercase(new_column)),
    dt &amp;lt;&amp;lt;New Column("BMI", numeric, continuous,
            formula(703 * :weight / :height / :height)
    );
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 19:57:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Determining-if-a-column-exists/m-p/55586#M31410</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2018-04-26T19:57:32Z</dc:date>
    </item>
  </channel>
</rss>

