<?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: How to check if a list contents is all numeric without loops in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20478#M18630</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/people/Craige@JMP"&gt;Craige@JMP&lt;/A&gt;​ Thanks, that worked a charm and I'm sure it something I will use again with other try statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Sep 2016 06:58:16 GMT</pubDate>
    <dc:creator>stephen_pearson</dc:creator>
    <dc:date>2016-09-20T06:58:16Z</dc:date>
    <item>
      <title>How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20472#M18624</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt; &lt;BR /&gt;I am writing some code which imports data and I would like to do some data checking similar to MessyTables for python.&lt;BR /&gt; &lt;BR /&gt;Data can be accidentally imported as character due to "NULL" or similar being present in the data. After removing the common instances of these I would like to check the data again to see if it is numeric.&lt;BR /&gt;The easiest way to do this is to use Try() and Matrix() after removing any "" around items in the list.&lt;BR /&gt;I could loop through the columnKeys and if the Num() conversion fails trigger a Throw(), this would be wasteful if the table is long and the column has many unique numbers.&lt;BR /&gt; &lt;BR /&gt;The code below writes an error to the long, which is fine. However it also triggers a JMP Alert window once I incorporate it into my add-in but not if I run it directly.&lt;BR /&gt; &lt;BR /&gt;Any suggestions of alternatives to check if a list is numeric or to suppress the JMP Alert dialog?&lt;BR /&gt; &lt;BR /&gt;Thanks,&lt;BR /&gt; &lt;BR /&gt;Stephen&lt;BR /&gt; &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Check Data",
Add Rows( 2 ),
New Column( "Column 1", Character, "Nominal", Set Values( {"+1%", "2", "-45"} ) )
);

a = Column(dt, "Column 1" ) &amp;lt;&amp;lt; Get Values;

Try(
b = Matrix( Parse( Substitute( Char( a ), "\!"", "", " " ) ) );
Show( "Converted to Numeric." );
Show(b);
,
Show( "Not all Numeric..." );
Show(a);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:35:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20472#M18624</guid>
      <dc:creator>stephen_pearson</dc:creator>
      <dc:date>2018-02-12T21:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20473#M18625</link>
      <description>&lt;P&gt;I find the easiest way to check to see if an imported column should actually be numeric, when in fact it was imported as character is to use this simple line of code. It returns the number of numeric values found:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;numberofnumerics = Col Number(num(&amp;lt;the target column&amp;gt;));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can also get a ratio of the number of numerics to the number of non blank columns&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ratio = Col Number(num(&amp;lt;the target column&amp;gt;)) / Col Number(&amp;lt;the target column&amp;gt;);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:36:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20473#M18625</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-02-12T21:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20474#M18626</link>
      <description>&lt;P&gt;This seems pretty fast. It just uses JMPs feature(?) where it just turns non-numeric values into missing values if the column is specified numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Edit for speed*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;lista =  {"+1%", "2", "-45", ""};
dt = New Table( "Check Data",
  New Column( "Character", Character, "Nominal", Set Values( lista ) ),
  New Column("Numeric", Numeric, Set Values( lista )),
  invisible
);
if( ColNMissing(Column(dt, "Character")) ==  ColNMissing(Column(dt, "Numeric")),
       ret = as list(Column(dt, "Numeric") &amp;lt;&amp;lt; get values),
       ret = Expr(print("Non-Convertable"));
);
close(dt, no save);
ret;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:37:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20474#M18626</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2018-02-12T21:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20475#M18627</link>
      <description>&lt;P&gt;Here's a variation on your original idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Check Data",
  Add Rows( 2 ),
  New Column( "Column 1", Character, "Nominal", Set Values( {"1", "2%", "-45"} ) )
);
a = Column(dt, "Column 1" ) &amp;lt;&amp;lt; Get Values;
try(parse("["||concatitems(a,",")||"]"),"nope");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:37:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20475#M18627</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-12T21:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20476#M18628</link>
      <description>&lt;P&gt;and to suppress the log messages:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Check Data",
    Add Rows( 2 ),
    New Column( "Column 1", Character, "Nominal", Set Values( {"1", "2", "-45"} ) )
);
 
a = Column( dt, "Column 1" ) &amp;lt;&amp;lt; Get Values;
cap = Log Capture(
    Try(
        Parse( "[" || Concat Items( a, "," ) || "]" );
        result = "ok";
    ,
        result = "bad"
    )
);
Show( result );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/message/226416" target="_blank"&gt;Re: how to bypass parse("a+b)") error?&lt;/A&gt;​&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; discussed logcapture and try.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;edit: removed redundant assignment to result.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:38:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20476#M18628</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-12T21:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20477#M18629</link>
      <description>&lt;P&gt;Finally, to suppress the dialog, use the BatchInteractive function.&amp;nbsp; Notice there are two calls, one before, and one after.&amp;nbsp; If you leave JMP running in the BatchInteractive(1) state, you'll have a hard time closing JMP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Check Data",
    Add Rows( 2 ),
    New Column( "Column 1", Character, "Nominal", Set Values( {"1", "2a", "-45"} ) )
);
a = Column( dt, "Column 1" ) &amp;lt;&amp;lt; Get Values;
Batch Interactive(1);
cap = Log Capture(
    Try(
        Parse( "[" || Concat Items( a, "," ) || "]" );
        result = "ok";
    ,
        result = "bad"
    )
);
Batch Interactive(0);
Show( result );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 21:35:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20477#M18629</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-02-12T21:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20478#M18630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/people/Craige@JMP"&gt;Craige@JMP&lt;/A&gt;​ Thanks, that worked a charm and I'm sure it something I will use again with other try statements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Sep 2016 06:58:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/20478#M18630</guid>
      <dc:creator>stephen_pearson</dc:creator>
      <dc:date>2016-09-20T06:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/34462#M20400</link>
      <description>&lt;P&gt;Probably should remove any missing values from the list as that will cause issues as well.&amp;nbsp;&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);
a = {"1", "2", "", "45", "", "3"};
x = repeat(1, nitems(a));
x[loc(a, "")] = 0;
a = a[loc(x)];
Batch Interactive(1);
cap = Log Capture(
    Try(
        Parse( "[" || Concat Items( a, "," ) || "]" );
        result = "ok";
    ,
        result = "bad"
    )
);
Batch Interactive(0);
Show( result );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jan 2017 23:18:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/34462#M20400</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2017-01-12T23:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a list contents is all numeric without loops</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/51041#M28980</link>
      <description>Thank you! I've been looking for sth like this for hours.</description>
      <pubDate>Sat, 10 Feb 2018 21:17:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-check-if-a-list-contents-is-all-numeric-without-loops/m-p/51041#M28980</guid>
      <dc:creator>gerd</dc:creator>
      <dc:date>2018-02-10T21:17:53Z</dc:date>
    </item>
  </channel>
</rss>

