<?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 cycle a script through multiple csv files in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335569#M58306</link>
    <description>&lt;P&gt;I looked at this but it doesn't seem to fit my needs. It will just open up individual jmp dt's. The column #'s are dynamic, based on the time range for each process file.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Nov 2020 15:40:06 GMT</pubDate>
    <dc:creator>aliegner1</dc:creator>
    <dc:date>2020-11-19T15:40:06Z</dc:date>
    <item>
      <title>how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335442#M58287</link>
      <description>&lt;P&gt;following up on a previous post, I've got a script that stacks and formats an unwieldy csv file.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Help-doing-a-table-transform-and-converting-a-timestamp/td-p/303091" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/Help-doing-a-table-transform-and-converting-a-timestamp/td-p/303091&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My next question for help is how can I get this to then repeat on a group of csv's in a folder, capturing the filename as one of the columns, ideally stacking them as well. aka step1, step2, step3, step4 files.&lt;/P&gt;&lt;P&gt;Stacking a single csv creates a 400k row output. Will I risk crashing if I merge 4 ot 8 or 10 of these csv's?&lt;/P&gt;&lt;P&gt;Maybe extra would be to then go cycle again through the next folder in the parent folder, creating a new combined step file?&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);

//Prompt to select and open an MS Excel file
dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );

// Get the column names from the data table
colNames = dt &amp;lt;&amp;lt; get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);

// Stack the data
dtStack = dt &amp;lt;&amp;lt; Stack(
	columns(
		colNames
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	Output Table( "Stacked_Data" )
);

//label the 1st column to Lamda
:Column 1 &amp;lt;&amp;lt; Set Name("Lamda");
:Lamda &amp;lt;&amp;lt; Modeling Type(nominal);

// Create a new JMP DateTime column
dtStack &amp;lt;&amp;lt; New Column( "Timestamp",
	Numeric,
	"Continuous",
	Format( "d/m/y h:m:s", 26, 3 ),
	Input Format( "d/m/y h:m:s", 0 ),
	Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp &amp;lt;&amp;lt; delete formula;

// Create the Time variable column
dtstack &amp;lt;&amp;lt; New Column( "Time",
	Numeric,
	"Continuous",
	Format( "hr:m:s", 17, 3 ),
	Input Format( "hr:m:s", 0 ),
	Formula( Time Of Day( :Timestamp ) )
);

//Create Absolute Time column, uses if&amp;gt;then error checking for Lamda group changing
dtstack &amp;lt;&amp;lt; New Column( "AbsTime",
	Numeric,
	"Continuous",
	Format( "Fixed Dec", 12, 1 ),
	Formula(
		If( Row() == 1 | :Lamda != Lag( :Lamda ),
			0,
			Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
		)
	),
);
// Remove formula to convert column to static values
dtStack:AbsTime &amp;lt;&amp;lt; delete formula;

// Get rid of no longer needed "Label" column
dtStack &amp;lt;&amp;lt; delete columns( "Label" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:22:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335442#M58287</guid>
      <dc:creator>aliegner1</dc:creator>
      <dc:date>2023-06-10T23:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335472#M58290</link>
      <description>&lt;P&gt;Basically, all you have to do, is to&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use "Files In Directory() to get the list of files to be processed&lt;/LI&gt;
&lt;LI&gt;Set up a data table to be used for the final data table( dtFinal )&lt;/LI&gt;
&lt;LI&gt;Use a For() loop to loop across all of the files found in the directory creating the deStack table
&lt;OL&gt;
&lt;LI&gt;Add the Source column to dtStack&lt;/LI&gt;
&lt;LI&gt;Concatenate dtStack to the dtFinal table&lt;/LI&gt;
&lt;LI&gt;Close the dtStack and dt data tables&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Below is your script modified with the above items.&amp;nbsp; The code is not tested, and you have to add in the directory etc. to read the files from.&amp;nbsp; It should give you a real good starting point for getting your final product&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//Prompt to select and open an MS Excel file
//dt = Open( Pick File( "Select Excel File", "C:\Users\folder\", {"Excel Files|csv;xlsx;xls", "All Files|*"}, 1, 0 ), Invisible );

// Get a list of files from the directory
fileList = Files In Directory( &amp;lt;path to your directory? );

// Create a skeleton data table to end up being the combined data table
dtFinal = New Table("Final");

// Loop across all of the files found in the directory and read them in
For(i = 1, i &amp;lt;= N Items( fileList ), i++,

dt = open( &amp;lt;path to your directory\&amp;gt; || fileList[i] );

// Get the column names from the data table
colNames = dt &amp;lt;&amp;lt; get column names;
// Remove the 1st col from the list
remove from(colNames,1,1);

// Stack the data
dtStack = dt &amp;lt;&amp;lt; Stack(
	columns(
		colNames
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	Output Table( "Stacked_Data" )
);

//label the 1st column to Lamda
:Column 1 &amp;lt;&amp;lt; Set Name("Lamda");
:Lamda &amp;lt;&amp;lt; Modeling Type(nominal);

// Create a new JMP DateTime column
dtStack &amp;lt;&amp;lt; New Column( "Timestamp",
	Numeric,
	"Continuous",
	Format( "d/m/y h:m:s", 26, 3 ),
	Input Format( "d/m/y h:m:s", 0 ),
	Formula( Informat( Word( 1, :Label, "Z" ), "d/m/y h:m:s" ) )
);
// Remove formula to convert column to static values
dtStack:Timestamp &amp;lt;&amp;lt; delete formula;

// Create the Time variable column
dtstack &amp;lt;&amp;lt; New Column( "Time",
	Numeric,
	"Continuous",
	Format( "hr:m:s", 17, 3 ),
	Input Format( "hr:m:s", 0 ),
	Formula( Time Of Day( :Timestamp ) )
);

//Create Absolute Time column, uses if&amp;gt;then error checking for Lamda group changing
dtstack &amp;lt;&amp;lt; New Column( "AbsTime",
	Numeric,
	"Continuous",
	Format( "Fixed Dec", 12, 1 ),
	Formula(
		If( Row() == 1 | :Lamda != Lag( :Lamda ),
			0,
			Lag( :AbsTime ) + (:Timestamp - Lag( :Timestamp ))
		)
	),
);
// Remove formula to convert column to static values
dtStack:AbsTime &amp;lt;&amp;lt; delete formula;

// Get rid of no longer needed "Label" column
dtStack &amp;lt;&amp;lt; delete columns( "Label" );

// Add filename as a column to the data table
dtStack &amp;lt;&amp;lt; new column( "Source", character, set each value( filename[i] ) );

// Concatenate to final table
dtFinal &amp;lt;&amp;lt; concatenate( dtStack, append to first table(1) );

// Clean up
close( dtStack, nosave );
close( dt, nosave );

// End For() Loop
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Nov 2020 07:54:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335472#M58290</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-11-19T07:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335474#M58291</link>
      <description>&lt;P&gt;Also check out Multiple File Import. It loads CSV files, concatenates them if they have the same columns, and can optionally add the file name column.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 10:20:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335474#M58291</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-11-19T10:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335566#M58305</link>
      <description>&lt;P&gt;Awesome. It seems to be working, but then errors out after the first file w/ an&lt;/P&gt;&lt;P&gt;"Name Unresolved: filenam}1} in access or evaluation of 'filename' , filename/*###*/"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any thoughts?&lt;/P&gt;&lt;P&gt;I also adjusted the script to do a select folder popup, i assume that isn't the problem.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Get a list of files from the directory
dir = Pick Directory( "Select a directory", "C:\Users\folder\");
fileList = Files In Directory( dir );

// Create a skeleton data table to end up being the combined data table
dtFinal = New Table("Final");

// Loop across all of the files found in the directory and read them in
For(i = 1, i &amp;lt;= N Items( fileList ), i++,

dt = open( dir || fileList[i] );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Nov 2020 15:38:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335566#M58305</guid>
      <dc:creator>aliegner1</dc:creator>
      <dc:date>2020-11-19T15:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335569#M58306</link>
      <description>&lt;P&gt;I looked at this but it doesn't seem to fit my needs. It will just open up individual jmp dt's. The column #'s are dynamic, based on the time range for each process file.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 15:40:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335569#M58306</guid>
      <dc:creator>aliegner1</dc:creator>
      <dc:date>2020-11-19T15:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to cycle a script through multiple csv files</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335570#M58307</link>
      <description>&lt;P&gt;Looks like the code wants to use filelist rather than filename for the list of file names. The one near the end.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 15:48:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-cycle-a-script-through-multiple-csv-files/m-p/335570#M58307</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-11-19T15:48:33Z</dc:date>
    </item>
  </channel>
</rss>

