cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
afterword
Level IV

Saving an Empty Table with JSL

I'm opening several tables from a database, and then saving those into CSV files. The script works fine as long as the table has data, but empty tables (which I also want to save to show that they're empty) give me this error:

Data table is empty.

The file could not be saved.
Unable to save file.{2}

I can manually save the tables in JMP format, but not as a text export. Any ideas?
3 REPLIES 3
JensRiege
Level IV

Re: Saving an Empty Table with JSL

If you use the 'Is Empty()' function you can use an if statement to only save the data when the table is not empty:
Example:

dt = Open( "Path\DataTable" );
If( Is Empty( dt ), 
// Then Do this if the table is not empty:
	dt << Save( "Path\DataTable" )
, 
// Else Do nothing
	Print( "the table is empty and will not be saved" )
);
Craige_Hales
Super User

Re: Saving an Empty Table with JSL

@chungwei 

I recently stumbled into this error message and was quite surprised.

Then I realized I'd made a new table with only the default "Column 1" and no rows.

I would prefer the table be saved as an empty table, but in my case the solution was as simple as naming the only column when I created the table.

The original report was apparently doing something other than the NewTable() function, so naming the column might have been harder.

sentinelDt = New Table( "sentinel", "private", New Column( "a") ); // needs a col name to save it with no rows!
sentinelDt << save( root || sentinelName );

 

Craige
JensRiege
Level IV

Re: Saving an Empty Table with JSL

After some further reading in the forum I realized that the Is Empty() function does not say whether the table has data in it... I saw a comment that it is better to use N Row (dt) to do this:

 

If( N Row( dt ) == 0, 
    // then
	Print( "Data table is empty" );

    // else
	Print( "Data table is not empty" );
);