<?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: Convert data to numeric, Only If Appropriate! in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106700#M39050</link>
    <description>&lt;P&gt;For the most part it worked, but upon further inspection, there is a case where strange things happen.&lt;BR /&gt;I have some codes that are numbers with dashes in them.&amp;nbsp; I would expect them to remain as character.&lt;/P&gt;&lt;P&gt;But this is what JMP&amp;nbsp;does.&amp;nbsp;&lt;/P&gt;&lt;P&gt;num("100-0001-01") results in&amp;nbsp;-56928614400&lt;/P&gt;&lt;P&gt;I do not know how it comes up with that, but because it's not missing the code accepts this as a number.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 19:30:25 GMT</pubDate>
    <dc:creator>pcarroll1</dc:creator>
    <dc:date>2019-01-16T19:30:25Z</dc:date>
    <item>
      <title>Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106692#M39045</link>
      <description>&lt;P&gt;&amp;nbsp;&amp;nbsp; I work with data stored in a table as Parameter and value.&amp;nbsp; Since the value may be a character for some Parameters the data type in the database is Character.&amp;nbsp; Pulling the data into JMP with an SQL script is easy and Splitting the data by Parameter is also easy.&amp;nbsp; But now I have a table of columns where I'd like to convert some of the columns to numeric, but others I do not. I tried this but to my surprise JMP happily converted all columns to numeric, throwing out the information that was truly character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Tcols = dt &amp;lt;&amp;lt; Get Column Names(String);
For(i=2, i&amp;lt;=n items(Tcols), i++,
try(column(dt,i) &amp;lt;&amp;lt; Data Type(Character);
    column(dt,i) &amp;lt;&amp;lt; Modeling Type("Nominal"));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I do a test to convert only columns where the data is appropriately numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 19:48:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106692#M39045</guid>
      <dc:creator>pcarroll1</dc:creator>
      <dc:date>2019-01-16T19:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106693#M39046</link>
      <description>&lt;P&gt;Here is a simple example that tests the first 10 rows of each column, and if no non numeric values are found, it converts the column to numeric&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// set all columns to character
For( i = 1, i &amp;lt;= N Cols( dt ), i++,
	Column( i ) &amp;lt;&amp;lt; set data type( character )
);

// Convert only numerics
For( i = 1, i &amp;lt;= N Cols( dt ), i++,
	isNumeric = "NO";
	For( theRow = 1, theRow &amp;lt;= 10, theRow++,
		If( Column( i )[theRow] != "" &amp;amp; Is Missing( Num( Column( i )[theRow] ) ) == 1,
			isNumeric = "NO";
			Break();
		,
			isNumeric = "YES"
		)
	);
	If( isNumeric == "YES",
		Column( i ) &amp;lt;&amp;lt; set data type( numeric )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 17:29:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106693#M39046</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-01-16T17:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106698#M39048</link>
      <description>&lt;P&gt;Thanks. This worked.&lt;BR /&gt;And I copied in the wrong code above. It should have been.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Tcols = dt &amp;lt;&amp;lt; Get Column Names(String);

For(i=2, i&amp;lt;=n items(Tcols), i++,

try(column(dt,i) &amp;lt;&amp;lt; Data Type(Numeric);

column(dt,i) &amp;lt;&amp;lt; Modeling Type("Continuous"));

);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 19:48:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106698#M39048</guid>
      <dc:creator>pcarroll1</dc:creator>
      <dc:date>2019-01-16T19:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106700#M39050</link>
      <description>&lt;P&gt;For the most part it worked, but upon further inspection, there is a case where strange things happen.&lt;BR /&gt;I have some codes that are numbers with dashes in them.&amp;nbsp; I would expect them to remain as character.&lt;/P&gt;&lt;P&gt;But this is what JMP&amp;nbsp;does.&amp;nbsp;&lt;/P&gt;&lt;P&gt;num("100-0001-01") results in&amp;nbsp;-56928614400&lt;/P&gt;&lt;P&gt;I do not know how it comes up with that, but because it's not missing the code accepts this as a number.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 19:30:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106700#M39050</guid>
      <dc:creator>pcarroll1</dc:creator>
      <dc:date>2019-01-16T19:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106714#M39054</link>
      <description>&lt;P&gt;It's treating it as a date&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;MDYHMS(num("100-0001-01"))
//returns
//"01/01/0100 00:00:00"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you could maybe try to parse the characters into a matrix with quotes replaced with empty strings&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 = New Table( "Test",
	Add Rows( 4 ),
	New Column( "Column 1",
		Character,
		"Nominal",
		Set Values( {"A", "B", "C", "D"} )
	),
	New Column( "Column 2",
		Character,
		"Nominal",
		Set Values( {"100-0001-01", "2", "4", "8"} )
	),
	New Column( "Column 3",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"1", "2", "3", "4"} )
	)
);

for(i=1, i&amp;lt;=ncols(dt), i++, 
	col = Column(dt, i);
	values = col &amp;lt;&amp;lt; Get Values;
	Try(
		Parse(Substitute(char(values), "\!"", "", "{", "[", "}", "]"));
		col &amp;lt;&amp;lt; Data Type("Numeric") &amp;lt;&amp;lt; Modeling Type("Continuous");
	);
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 21:49:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/106714#M39054</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-01-16T21:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert data to numeric, Only If Appropriate!</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/107065#M39091</link>
      <description>&lt;P&gt;Vince,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Thanks for the insight.&amp;nbsp; I guess it's a tricky thing because depending upon the situation some characters can have different meanings (e.g. "-" or&amp;nbsp;"e")&amp;nbsp;.&amp;nbsp; Your code worked as you wrote it, but it failed on my set because of missing values.&amp;nbsp; Those could be handled by more arguments in the Substitute command to find and eliminate the string "", .&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Parse&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Substitute&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;char&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(values), &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"\!"\!"\!, "&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;""&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"\!""&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;""&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"{"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"["&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"}"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"]"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; However all of my Column 2&amp;nbsp;are&amp;nbsp;values that&amp;nbsp;could&amp;nbsp;be interpretted as dates&amp;nbsp;so this code also interpretted them as such.&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 = New Table( "Test",
	Add Rows( 4 ),
	New Column( "Column 1",
		Character,
		"Nominal",
		Set Values( {"A", "B", "C", "D"} )
	),
	New Column( "Column 2",
		Character,
		"Nominal",
		Set Values( {"100-0001-01", "100-0001-01", "100-0001-01", "100-0001-01"} )
	),
	New Column( "Column 3",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"1", "2", "", "4"} )
	)
);

dt = current data table();
for(i=1, i&amp;lt;=ncols(dt), i++, 
	col = Column(dt, i);
	values = col &amp;lt;&amp;lt; Get Values;
	Try(
		Parse(Substitute(char(values), "\!"\!"\!, ", "", "\!"", "", "{", "[", "}", "]"));
		col &amp;lt;&amp;lt; Data Type("Numeric") &amp;lt;&amp;lt; Modeling Type("Continuous");
	);
);&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;&amp;nbsp; &amp;nbsp;&amp;nbsp; Although not perfect, I can go with this or with txnelson's code because the column that it converts as a date is not important to me.&amp;nbsp; If I knew that it was being interpretted as a date, I could make that an exception.&amp;nbsp; I don't have dates in this set of data.&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 15:07:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-data-to-numeric-Only-If-Appropriate/m-p/107065#M39091</guid>
      <dc:creator>pcarroll1</dc:creator>
      <dc:date>2019-01-18T15:07:10Z</dc:date>
    </item>
  </channel>
</rss>

