<?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: JSL Table import - Selecting correct row as headers when desired row number is variable in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238431#M47098</link>
    <description>&lt;P&gt;1) I think two imports is probably the easiest way and can be made faster...&lt;/P&gt;&lt;P&gt;2) You'll need to specify more than just the columns to import, but the speedup will be worth it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="use the text import wizard to mark the unwanted columns" style="width: 880px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/20633iF7D3C56F48C554E2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="use the text import wizard to mark the unwanted columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;use the text import wizard to mark the unwanted columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Grab the source script, it has the JSL to omit columns" style="width: 831px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/20634i8CB2CFC49B0974DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Grab the source script, it has the JSL to omit columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Grab the source script, it has the JSL to omit columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(for 1000 omitted columns it might be easier to edit the JSL than exclude with the GUI.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, you can tweak the source script. Below it reads the first 100 lines. It is fast because (1) everything about the columns is specified and (2) it stops after 100 lines. For this data I should have specified Labels(0) and DataStarts(1).&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;Open(
	"f:\logOriginalAntenna.txt",// 100MB file takes about 2 seconds to load 100 lines
	columns(
		Omitted Column( . ),// use the import wizard to
		Omitted Column( . ),// get a source script with
		Omitted Column( . ),// omitted columns
		New Column( "c000004",
			Numeric,
			"Continuous",
			Format( "yyyy-mm-ddThh:mm:ss", 23, 3 ),
			Input Format( "yyyy-mm-ddThh:mm:ss", 3 )
		),
		New Column( "c000005", Character, "Nominal" )
	),
	Import Settings(
		End Of Line( CRLF, CR, LF ),
		End Of Field( Tab, Comma, CSV( 1 ) ),
		Strip Quotes( 1 ),
		Use Apostrophe as Quotation Mark( 0 ),
		Use Regional Settings( 0 ),
		Scan Whole File( 1 ),
		Treat empty columns as numeric( 0 ),
		CompressNumericColumns( 0 ),
		CompressCharacterColumns( 0 ),
		CompressAllowListCheck( 0 ),
		Labels( 1 ),
		Column Names Start( 1 ),
		Data Starts( 2 ),
		Lines To Read( 100 ),// specify the number of rows
		Year Rule( "20xx" )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your files always have the same column ordering, then specifying the format explicitly (above) will mean JMP does not need to study the file before importing it. I think JMP still studies the &lt;EM&gt;entire&lt;/EM&gt; file even if you stop at 100 lines, so this could reduce the processing time, a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the files don't always have the same number of columns or order of columns, this won't work. You might be able to import the table, fix up the column names and data types, delete rows you don't want...using a single import.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2019 00:30:00 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2019-12-13T00:30:00Z</dc:date>
    <item>
      <title>JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238418#M47096</link>
      <description>&lt;P&gt;I have a script that uses an input list to pull files from a directory.&amp;nbsp; The file format is unusual so it takes some manipulation and each file is on the order of 60Mb so imports can take more time than I would want.&amp;nbsp; My issue is that most files have the desired header row on row 15 but about 10% of the files have a header that could be anywhere from row 10-14 and there is no way to know until i open the file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current solution is to have the script open the first 20 rows, search for the row that contains the headers and assign that row number to a variable, close that dt, then reopen but using the variable as the header and variable + 1 as the first line.&amp;nbsp; It works but it means I'm opening these files twice, though one is a limited preview only.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Is there a better way to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) And while I'm asking, is there a way to import a table but only import the columns that I want, based on name?&amp;nbsp; My files have about 1000 columns and I only need about 15 of them.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 21:50:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238418#M47096</guid>
      <dc:creator>SamKing</dc:creator>
      <dc:date>2019-12-12T21:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238431#M47098</link>
      <description>&lt;P&gt;1) I think two imports is probably the easiest way and can be made faster...&lt;/P&gt;&lt;P&gt;2) You'll need to specify more than just the columns to import, but the speedup will be worth it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="use the text import wizard to mark the unwanted columns" style="width: 880px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/20633iF7D3C56F48C554E2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="use the text import wizard to mark the unwanted columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;use the text import wizard to mark the unwanted columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Grab the source script, it has the JSL to omit columns" style="width: 831px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/20634i8CB2CFC49B0974DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Grab the source script, it has the JSL to omit columns" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Grab the source script, it has the JSL to omit columns&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(for 1000 omitted columns it might be easier to edit the JSL than exclude with the GUI.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, you can tweak the source script. Below it reads the first 100 lines. It is fast because (1) everything about the columns is specified and (2) it stops after 100 lines. For this data I should have specified Labels(0) and DataStarts(1).&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;Open(
	"f:\logOriginalAntenna.txt",// 100MB file takes about 2 seconds to load 100 lines
	columns(
		Omitted Column( . ),// use the import wizard to
		Omitted Column( . ),// get a source script with
		Omitted Column( . ),// omitted columns
		New Column( "c000004",
			Numeric,
			"Continuous",
			Format( "yyyy-mm-ddThh:mm:ss", 23, 3 ),
			Input Format( "yyyy-mm-ddThh:mm:ss", 3 )
		),
		New Column( "c000005", Character, "Nominal" )
	),
	Import Settings(
		End Of Line( CRLF, CR, LF ),
		End Of Field( Tab, Comma, CSV( 1 ) ),
		Strip Quotes( 1 ),
		Use Apostrophe as Quotation Mark( 0 ),
		Use Regional Settings( 0 ),
		Scan Whole File( 1 ),
		Treat empty columns as numeric( 0 ),
		CompressNumericColumns( 0 ),
		CompressCharacterColumns( 0 ),
		CompressAllowListCheck( 0 ),
		Labels( 1 ),
		Column Names Start( 1 ),
		Data Starts( 2 ),
		Lines To Read( 100 ),// specify the number of rows
		Year Rule( "20xx" )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your files always have the same column ordering, then specifying the format explicitly (above) will mean JMP does not need to study the file before importing it. I think JMP still studies the &lt;EM&gt;entire&lt;/EM&gt; file even if you stop at 100 lines, so this could reduce the processing time, a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the files don't always have the same number of columns or order of columns, this won't work. You might be able to import the table, fix up the column names and data types, delete rows you don't want...using a single import.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 00:30:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238431#M47098</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-12-13T00:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238474#M47113</link>
      <description>Thanks Craige. For the initial import to get the row with the column headers I used your advice and used the omit column for columns 2 to 1000 so I only import column 1 with 20 rows, grab what I need then close it. Then I reopen the file but using the information from the first part of the loop to properly select the column header row.&lt;BR /&gt;&lt;BR /&gt;I do wish there was a better way to import specific columns for the 2nd part of the loop. In my situation the columns on my raw input file are likely to change order and quantity over time without me knowing. Would be cool if JMP had the ability to specify by name only the columns you want to import.</description>
      <pubDate>Fri, 13 Dec 2019 15:58:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238474#M47113</guid>
      <dc:creator>SamKing</dc:creator>
      <dc:date>2019-12-13T15:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238476#M47114</link>
      <description>&lt;P&gt;glad that will help, seems like a worthy wish list item.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 16:17:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/238476#M47114</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2019-12-13T16:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/242840#M47930</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm searching for a way to shorten the code for the import of these .csv-like files.&amp;nbsp; I have one import that now has about 1000 columns and another with about 360, and this loops through hundreds of files now in a list called "FileList".&amp;nbsp; I only want to import column 1 for the reasons stated above.&amp;nbsp; My current code looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( x = 1, x &amp;lt;= N Items( FileList ), x++,
		dt = Open(
			FileList[x],
			eval(columns(
				New Column( "Col1", Character, "Nominal" ), 
				Omitted Column( . ),
                Omitted Column( . ),
                Omitted Column( . ), &lt;FONT color="#FF0000"&gt;(repeated 400 times!)&lt;/FONT&gt;
			),
			Import Settings(
				End Of Line( CRLF, CR, LF ),
				End Of Field( Spaces, Space, CSV( 0 ) ),
				Strip Quotes( 1 ),
				Column Names Start( 1 ),
				Data Starts( 1 ),
			),
			//invisible
		);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But i was trying to figure out how to use an eval() type expression but I'm not doing it correctly.&amp;nbsp; I've tried the eval() expression in various places but can't seem to get it.&amp;nbsp; I'm new to eval().&amp;nbsp; I'm thinking that maybe my issue is that my variable "Omit" ends up being a string but enclosed in quotes??&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;FONT color="#339966"&gt;	Omit&lt;/FONT&gt; = repeat("Omitted Column( . ),",400)||"Omitted Column( . )";

	For( x = 1, x &amp;lt;= N Items( FileList ), x++,
		dt = Open(
			FileList[x],
			&lt;FONT color="#FF0000"&gt;eval(&lt;/FONT&gt;columns(
				New Column( "Col1", Character, "Nominal" ), 
				&lt;FONT color="#339966"&gt;Omit&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;);&lt;/FONT&gt;
			),
			Import Settings(
				End Of Line( CRLF, CR, LF ),
				End Of Field( Spaces, Space, CSV( 0 ) ),
				Strip Quotes( 1 ),
				Column Names Start( 1 ),
				Data Starts( 1 ),
			),
		);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 18:45:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/242840#M47930</guid>
      <dc:creator>SamKing</dc:creator>
      <dc:date>2020-01-24T18:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Table import - Selecting correct row as headers when desired row number is variable</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/242929#M47942</link>
      <description>&lt;P&gt;I think you are right; you might need to use parse() to convert the string to an expression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's another approach you can take which avoids strings and manipulates the expressions directly:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// testing data (I modified your end of field with a tab, below)
filelist = {"$sample_data\..\Import Data\bigclass.txt"};
x = 1; 

// build an expression with a placeholder COLUMNSEXPR
openstmt = Expr(
	Open(
		FileList[x],
		COLUMNSEXPR, // &amp;lt;&amp;lt; placeholder for columns(...)
		Import Settings( End Of Line( CRLF, CR, LF ), End Of Field( tab, CSV( 0 ) ), 
		Strip Quotes( 1 ), Column Names Start( 1 ), Data Starts( 1 ) )
	)
);

// if you run the openstmt function now, it will import all the columns
//
// eval(openstmt);

// build a list using {} to make it easy to manipulate
COLUMNSLIST = {};
// insert the column you want to keep
Insert Into( COLUMNSLIST, Expr( New Column( "Col1", Character, "Nominal" ) ) );
// insert 5 omit columns...
For( i = 1, i &amp;lt; 5, i += 1,
	Insert Into( COLUMNSLIST, Expr( Omitted Column( . ) ) )
);
// COLUMNSLIST looks like this:
//{New Column( "Col1", Character, "Nominal" ), Omitted Column( . ),
//Omitted Column( . ), Omitted Column( . ), Omitted Column( . )}

// convert the {...} to columns(...)
Substitute Into( COLUMNSLIST, Expr( {} ), Expr( columns ) );

//show(nameexpr(COLUMNSLIST)); shows this:
//columns(New Column("Col1", Character, "Nominal"), 
//Omitted Column(.), Omitted Column(.), 
//Omitted Column(.), Omitted Column(.))
//
// if you leave out the nameexpr() it will (try to) evaluate rather than
// retrieving the expression for display. columns() is not a function in
// JSL, so evaluating makes an error message.

// nameexpr(openstmt) still show COLUMNSEXPR. replace it:
Substitute Into( openstmt, Expr( COLUMNSEXPR ), Name Expr( COLUMNSLIST ) );

// nameexpr(openstmt) is now 
//Open(
//	FileList[x],
//	columns(
//		New Column( "Col1", Character, "Nominal" ),
//		Omitted Column( . ),
//		Omitted Column( . ),
//		Omitted Column( . ),
//		Omitted Column( . )
//	),
//	Import Settings(
//		End Of Line( CRLF, CR, LF ),
//		End Of Field( tab, CSV( 0 ) ),
//		Strip Quotes( 1 ),
//		Column Names Start( 1 ),
//		Data Starts( 1 )
//	)
//)

Eval( openstmt ); // reads just the first column of the table&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also do something similar by manipulating text, rather than expressions, and then&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;eval(parse( " the text you built ") )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Use the technique you are most comfortable with; there will be a minor speed improvement manipulating the expressions, but insignificant compared to reading a file from disk.&lt;/P&gt;&lt;P&gt;Note that the final statement above still depends on the value of X to choose a file to open, so there is no need to rebuild the expression.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 23:55:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Table-import-Selecting-correct-row-as-headers-when-desired/m-p/242929#M47942</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-01-24T23:55:35Z</dc:date>
    </item>
  </channel>
</rss>

