<?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: Summary of multiple CSV files in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33818#M20039</link>
    <description>&lt;P&gt;Here is what the data looks like within a CSV file. The file name is also the patient identifier. How can I get it to summarize by column heading and create a table of the summarized data with the file identifier in a column? You can see what the file name looks like at the bottom on the screen shot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could convert all the CSVs to JMP files? Just not sure it would help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know if the Data Table Tools add-in would work for this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Dec 2016 23:32:59 GMT</pubDate>
    <dc:creator>briankwalsh</dc:creator>
    <dc:date>2016-12-19T23:32:59Z</dc:date>
    <item>
      <title>Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31036#M19659</link>
      <description>&lt;P&gt;How do I direct JMP to a file folder on my desktop that have about 400 CSV files like a database, create a bunch of columns and create a summary table with 1 row per file? I can do this individually, but it takes forever and I was hoping I could develop a script to automate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 19:32:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31036#M19659</guid>
      <dc:creator>briankwalsh</dc:creator>
      <dc:date>2016-12-01T19:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31051#M19668</link>
      <description>&lt;P&gt;So I'm making a few assumptions about this. I could be off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All csv files have the same columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you want to create an aggregate summary (mean for example) of each column for each file. &amp;nbsp;&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);
dir = pick directory();
files = files in directory(dir);

dt = New Table("concat", New Column("File", character));
for(i=1, i&amp;lt;=nitems(files), i++, 

	if(endswith(files[i], "csv"), //just a check to make sure it's a csv
		//break();
		dt1 = open(dir||files[i], private);
		dt1 &amp;lt;&amp;lt; New Column("File", character, set each value(files[i]));
		dt&amp;lt;&amp;lt;concatenate(dt1, append to first table);
		close(dt1, no save);
	)
);

dt_Sum = dt &amp;lt;&amp;lt; Summary( //you'll have to put which statistics you want for your column names here
	Group( :File ),
	Mean( :ColumnA ),
	Mean( :ColumnB ),
	Mean( :ColumnC ),
	Mean( :ColumnD ),
	Freq( "None" ),
	Weight( "None" )
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 21:14:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31051#M19668</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2016-12-01T21:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31057#M19671</link>
      <description>&lt;P&gt;(Ignore this answer; Vince has a much better approach.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A variation on Vince's answer, if you want per-file statistics. &amp;nbsp;I also imagine the columns are consistent...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;path = "$desktop/csvFiles/";
files = Files In Directory( path );

answers = New Table( "Summary",
	New Column( "N Rows", Numeric, "Continuous", Format( "Fixed Dec", 12, 0 ), Set Values( [] ) ),
	New Column( "Mean(x)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "Mean(y)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "Mean(z)", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "sourceFile", character )
);


For( iFile = 1, iFile &amp;lt;= N Items( files ), iFile += 1,
	file = path || files[iFile];
	dt = Open( file, "text" );
	dt2 = dt &amp;lt;&amp;lt; Summary( Mean( :x ), Mean( :y ), Mean( :z ), Freq( "None" ), Weight( "None" ) );
	answers &amp;lt;&amp;lt; addrows( 1 );
	answers:sourceFile = file || " " || Format( Creation Date( file ), "m/d/y h:m:s" );
	answers:N Rows = dt2:N Rows[1];
	answers:name( "Mean(x)" ) = dt2:name( "Mean(x)" )[1];
	answers:name( "Mean(y)" ) = dt2:name( "Mean(y)" )[1];
	answers:name( "Mean(z)" ) = dt2:name( "Mean(z)" )[1];
	Close( dt, nosave ); // linked table closes too
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;my files looked like this&lt;/P&gt;
&lt;P&gt;x,y,z&lt;BR /&gt;1,2,3&lt;BR /&gt;4,5,6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the table script from a file I made by hand to get the Summary script. &amp;nbsp;There might be a better way to copy the variables; in JMP 13 you could use the ideas &lt;A href="https://community.jmp.com/t5/Uncharted/Data-table-subscripting/ba-p/21013" target="_self"&gt;here&lt;/A&gt; to assign a whole row in one statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 22:00:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/31057#M19671</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2016-12-01T22:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33491#M19881</link>
      <description>&lt;P&gt;Sorry for the delay. Was on service and having to take care of patients. Now just getting back to this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No they don't always have the same column (A, B, C, etc.) but they do have the same name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brian&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2016 17:48:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33491#M19881</guid>
      <dc:creator>briankwalsh</dc:creator>
      <dc:date>2016-12-10T17:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33646#M19953</link>
      <description>&lt;P&gt;can you give a screenshot of two fake tables and what you want the end result to look like? &amp;nbsp;I can't figure out what you're asking. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 00:57:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33646#M19953</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2016-12-14T00:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33818#M20039</link>
      <description>&lt;P&gt;Here is what the data looks like within a CSV file. The file name is also the patient identifier. How can I get it to summarize by column heading and create a table of the summarized data with the file identifier in a column? You can see what the file name looks like at the bottom on the screen shot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could convert all the CSVs to JMP files? Just not sure it would help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know if the Data Table Tools add-in would work for this case?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 23:32:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33818#M20039</guid>
      <dc:creator>briankwalsh</dc:creator>
      <dc:date>2016-12-19T23:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33863#M20057</link>
      <description>&lt;P&gt;Summarized how? &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 17:47:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33863#M20057</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2016-12-21T17:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33867#M20058</link>
      <description>&lt;P&gt;Here is a variation on Vince's response; this allows different column names in each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Names Default to here(1);
dir = pick directory();
files = files in directory(dir);

//table to hold summary data
dts = New Table("Summary", New Column("filename", character));


for(i=1, i&amp;lt;=nitems(files), i++, //for each filename

	if(endswith(files[i], "csv"), //if file is a csv
	
		//open the file
		dt1 = open( dir||files[i], private );
		
		//add a row to the summary table
		dts &amp;lt;&amp;lt; Add Rows(1);
		
		//save the filename to the data table
		Column( dts, "filename" )[i] = files[i];
		
		//get list of columns
		cols = dt1 &amp;lt;&amp;lt; Get Column Names();
		
		//for each column
		for ( c=1, c &amp;lt;= N Items(cols), c++,
		
			//add mean column to summary table if it isn't already there
			if ( Contains( dts &amp;lt;&amp;lt; Get Column Names(); , Parse( Char( cols[c] ) || "_mean" ) ) &amp;lt; 1,
				dts &amp;lt;&amp;lt; New Column( Char( cols[c] ) || "_mean" );
			);
			
			//find the mean and write it to summary table
			Column( dts, Char( cols[c] ) || "_mean" )[i] = ColMean( Column( dt1, cols[c] ) );
			
			//add max column to summary table if it isn't already there
			if ( Contains( dts &amp;lt;&amp;lt; Get Column Names(); , Parse( Char( cols[c] ) || "_max" ) ) &amp;lt; 1,
				dts &amp;lt;&amp;lt; New Column( Char( cols[c] ) || "_max" );
			);
			
			//find the max and write it to summary table
			Column( dts, Char( cols[c] ) || "_max" )[i] = ColMax( Column( dt1, cols[c] ) );
			
		); //end loop each column
		
		//close file
		close(dt1, no save);
		
	); //end check for csv
	
); //end loop for each file&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Dec 2016 22:24:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33867#M20058</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2016-12-21T22:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33869#M20060</link>
      <description>&lt;P&gt;Here is my take on the script that is needed.&amp;nbsp; It is pretty simple and gets all numeric columns summarized, and brings along the Excel Sheet name as a new column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is edited based upon the issues found in the next reply&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dir = Pick Directory();
files = Files In Directory( dir );

dt = New Table( "concat", New Column( "File", character ) );
For( i = 1, i &amp;lt;= N Items( files ), i++, 

	If( Ends With( files[i], "csv" ), //just a check to make sure it's a csv
		// Open the file
		dt1 = Open( dir || files[i], private );
		//Get all of the numeric columns from the just opened file
		thecolumns = dt1 &amp;lt;&amp;lt; get column names( numeric );
		// Create an output table of one row that contains the summary
		// As many stats as desired can be added to the below to get all of the
		// ones that are needed
		dt2 = dt1 &amp;lt;&amp;lt; Summary( Mean( Eval( thecolumns ) ), Freq( "None" ), Weight( "None" ) );
		// Add the summary table to the summary table
		dt &amp;lt;&amp;lt; concatenate( dt2, append to first table );
		
		// Since what is wanted is the ID, not the file name, and the ID is
		// the Sheeet name in the Excel spreadsheet, one has to get that value
		// the the name of the data table, since that is where JMP 13 places the
		// sheet name
		dt:File[N Rows( dt ) ] = dt1 &amp;lt;&amp;lt; Get Name;
		// Close the no longer needed raw data table
		Close( dt1, no save );Close( dt2, no save );
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 00:57:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33869#M20060</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2016-12-23T00:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33875#M20064</link>
      <description>&lt;P&gt;I think you meant to append the summary tables instead of the data tables?&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 );
dir = Pick Directory();
files = Files In Directory( dir );

dt = New Table( "concat", New Column( "File", character ) );
For( i = 1, i &amp;lt;= N Items( files ), i++, 

	If( Ends With( files[i], "csv" ), //just a check to make sure it's a csv
		// Open the file
		dt1 = Open( dir || files[i] );
		//Get all of the numeric columns from the just opened file
		thecolumns = dt1 &amp;lt;&amp;lt; get column names( numeric );
		// Create an output table of one row that contains the summary
		// As many stats as desired can be added to the below to get all of the
		// ones that are needed
		dt1 &amp;lt;&amp;lt; Summary( Mean( Eval( thecolumns ) ), Freq( "None" ), Weight( "None" ), output table name("tmpdt"));
		// Add the summary table to the summary table
		dt &amp;lt;&amp;lt; concatenate( Data Table("tmpdt"), append to first table );
		// Since what is wanted is the ID, not the file name, and the ID is
		// the Sheeet name in the Excel spreadsheet, one has to get that value
		// the the name of the data table, since that is where JMP 13 places the
		// sheet name
		dt:File[N Rows( dt ) ] = dt1 &amp;lt;&amp;lt; Get Name;
		// Close the no longer needed raw data table
		Close( dt1, no save );
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Jan 2017 15:43:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33875#M20064</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2017-01-04T15:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Summary of multiple CSV files</title>
      <link>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33888#M20074</link>
      <description>&lt;P&gt;You are correct.....thanks for catching the mistake&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I modified my original entry to correct the mistakes you found&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 00:58:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Summary-of-multiple-CSV-files/m-p/33888#M20074</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2016-12-23T00:58:27Z</dc:date>
    </item>
  </channel>
</rss>

