<?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 do I save a subset of tables only? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345843#M59650</link>
    <description>&lt;P&gt;Below is a script that will create the Example data table you provided.&amp;nbsp; It will then create the subsets, and save each subset as a .txt file.&lt;/P&gt;
&lt;P&gt;All that needs to be done to run this example, is to change the line of code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;saveFolder = "C:\xxxxxxxxxxxxx\";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to what the actual path to the folder to save the files into, and then run the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create the example data table
New Table( "Example",
	Add Rows( 7 ),
	New Column( "City code", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [32, 160, 281, 325, 420, 511, 720] ) ),
	New Column( "Registration Number",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [320537648, 1600084082, 2821162566, 3250488500, 4200618843, 5110680174, 7200054737] )
	),
	New Column( "Registration Date",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [20201026, 20201020, 20201020, 20201024, 20201101, 20201027, 20200825] )
	)
);


// Here is the real code.....just change the saveFolder =    to the actual folder you want to
// save the files to
dt = Current Data Table();

// Create the subsets
dtSub = dt &amp;lt;&amp;lt; Subset( By( :City code ), 
	All rows, Selected columns only( 0 ), 
	columns( :Registration Number, :Registration Date ) );

saveFolder = "C:\xxxxxxxxxxxxx\";

For( i = 1, i &amp;lt;= N Items( dtSub ), i++,
	// Given the structure of the data tables created with a Subset using a By() clause
	//      City Code = 32
	// the Word() function retuns the "32" and it is added as the name of the file to save
	dtSub[i] &amp;lt;&amp;lt; Save( saveFolder || Word( -1, dtSub[i] &amp;lt;&amp;lt; get name, "=" ) || ".txt" )
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Jan 2021 18:35:33 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-01-05T18:35:33Z</dc:date>
    <item>
      <title>How do I save a subset of tables only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345802#M59649</link>
      <description>&lt;P&gt;Let's say we have a table with 3 columns (example below). I create a subset of tables by the "city code" column that will include all 3 columns.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;City code&lt;/TD&gt;&lt;TD&gt;Registration Number&lt;/TD&gt;&lt;TD&gt;Registration Date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;032&lt;/TD&gt;&lt;TD&gt;0320537648&lt;/TD&gt;&lt;TD&gt;20201026&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;160&lt;/TD&gt;&lt;TD&gt;1600084082&lt;/TD&gt;&lt;TD&gt;20201020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;281&lt;/TD&gt;&lt;TD&gt;2821162566&lt;/TD&gt;&lt;TD&gt;20201020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;325&lt;/TD&gt;&lt;TD&gt;3250488500&lt;/TD&gt;&lt;TD&gt;20201024&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;420&lt;/TD&gt;&lt;TD&gt;4200618843&lt;/TD&gt;&lt;TD&gt;20201101&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;511&lt;/TD&gt;&lt;TD&gt;5110680174&lt;/TD&gt;&lt;TD&gt;20201027&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;720&lt;/TD&gt;&lt;TD&gt;7200054737&lt;/TD&gt;&lt;TD&gt;20200825&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to save only the subset files as text files as follows: city code value.txt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the following jsl script on the forum which was very helpful in saving the files as text files. The issue is that the files are saved as city code = value.txt&lt;/P&gt;&lt;P&gt;The main data table is also saved a text file, which I don't want.&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;//Save as txt file

openDTs = {};

For( i = 1, i &amp;lt;= N Table(), i++,

     Insert Into( openDTs, Data Table( i ) )

);

For( i = 1, i &amp;lt;= N Items( openDTs ), i++,

     one_name = openDTS[i] &amp;lt;&amp;lt; get name;

     file_path = one_name || ".txt";

     openDTS[i] &amp;lt;&amp;lt; Save(file_path);

);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am new to both JMP and scripting, so any ideas are very much appreciated.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:02:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345802#M59649</guid>
      <dc:creator>CMG</dc:creator>
      <dc:date>2023-06-09T22:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I save a subset of tables only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345843#M59650</link>
      <description>&lt;P&gt;Below is a script that will create the Example data table you provided.&amp;nbsp; It will then create the subsets, and save each subset as a .txt file.&lt;/P&gt;
&lt;P&gt;All that needs to be done to run this example, is to change the line of code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;saveFolder = "C:\xxxxxxxxxxxxx\";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to what the actual path to the folder to save the files into, and then run the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create the example data table
New Table( "Example",
	Add Rows( 7 ),
	New Column( "City code", Numeric, "Continuous", Format( "Best", 12 ), Set Selected, Set Values( [32, 160, 281, 325, 420, 511, 720] ) ),
	New Column( "Registration Number",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [320537648, 1600084082, 2821162566, 3250488500, 4200618843, 5110680174, 7200054737] )
	),
	New Column( "Registration Date",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [20201026, 20201020, 20201020, 20201024, 20201101, 20201027, 20200825] )
	)
);


// Here is the real code.....just change the saveFolder =    to the actual folder you want to
// save the files to
dt = Current Data Table();

// Create the subsets
dtSub = dt &amp;lt;&amp;lt; Subset( By( :City code ), 
	All rows, Selected columns only( 0 ), 
	columns( :Registration Number, :Registration Date ) );

saveFolder = "C:\xxxxxxxxxxxxx\";

For( i = 1, i &amp;lt;= N Items( dtSub ), i++,
	// Given the structure of the data tables created with a Subset using a By() clause
	//      City Code = 32
	// the Word() function retuns the "32" and it is added as the name of the file to save
	dtSub[i] &amp;lt;&amp;lt; Save( saveFolder || Word( -1, dtSub[i] &amp;lt;&amp;lt; get name, "=" ) || ".txt" )
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jan 2021 18:35:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345843#M59650</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-01-05T18:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I save a subset of tables only?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345849#M59654</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;Thank you so much! Worked like a charm.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 19:16:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-save-a-subset-of-tables-only/m-p/345849#M59654</guid>
      <dc:creator>CMG</dc:creator>
      <dc:date>2021-01-05T19:16:00Z</dc:date>
    </item>
  </channel>
</rss>

