<?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: Import Multiple CSV Files from different folder, Update Value, and save CSV with different names in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434096#M68386</link>
    <description>&lt;P&gt;I'm not sure what your JSL did:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt: subjid &amp;lt;&amp;lt; :id1 &amp;lt;&amp;lt; Set Formula( If( :id2 == "a001", :id1 == "b001") )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The &amp;lt;&amp;lt; "send" operator should only appear once, and the column you are adding the formula to should be the left-hand-side. Then in the if statement, there should be a condition, followed by a value for the true case, and another value for the false case. Something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column( "likes",
	"character",
	formula( If( 
		Is Missing( name ), // first test
			"unknown", // if first test is true
		name == "KATIE", // second test
			"cats", // if second test is true
			"dogs"  // if second test is false
		) 
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is intended to create a new formula column of cats or dogs depending on the value in column name. If name is blank (missing), "unknown".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if your goal is to overwrite an existing column(s) based on values of other columns, perhaps an explicit loop would be better than a formula column:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;foreachrow(dt,
	if(
		name == "DANNY", // a test with ==
			name = "Dani"; // an assignment with =
			sex = "F";
		, /* else if */ name == "ROBERT",
			name = "Roberta";
			sex = "F";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;( &lt;LI-MESSAGE title="If Secrets" uid="39558" url="https://community.jmp.com/t5/Uncharted/If-Secrets/m-p/39558#U39558" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; might help understanding the commas and semicolons. ) That leaves rows unchanged, unless&amp;nbsp; the name matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice how the two examples are different:&lt;/P&gt;
&lt;P&gt;The first example must produce an answer in the if(...) that will be assigned to the formula's column. &lt;STRIKE&gt;If the column should be unchanged for that row, the formula's value must be the original value for the row.&lt;/STRIKE&gt;&amp;nbsp; Edit: sorry, that's wrong. Just make sure the formula column produces a value for every row.&lt;/P&gt;
&lt;P&gt;The second example only updates rows and columns it chooses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you plan to write out a CSV file (not save a JMP file), the formula expression you add to a column will not be saved (though the updated values from the formula will be.) I think you might want something more like the second example.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Nov 2021 14:38:01 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2021-11-08T14:38:01Z</dc:date>
    <item>
      <title>Import Multiple CSV Files from different folder, Update Value, and save CSV with different names</title>
      <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/433910#M68371</link>
      <description>&lt;P&gt;I have about 95 csv files with different column names saved under main data folder and 95 different sub-folders like \data\dataset1\dataset1.csv,&amp;nbsp;\data\dataset2\dataset2.csv, etc. id1 and id2 columns are common variables across all files. I want to to do the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Import all 95 csv files to JMP (using JMP Pro 16)&lt;/LI&gt;&lt;LI&gt;Update a value based on a condition across all 95 files: if (id1 = 'a001' then id2='b001')&lt;/LI&gt;&lt;LI&gt;Save updated csv files under different names in respective folders&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;First row is the file title and can't be removed. Column/variable names start at row 2 and data on row 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I managed to import all files by:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dt: Multiple File Import(&lt;BR /&gt;&amp;lt;&amp;lt;Set Folder(&lt;BR /&gt;"C:\Data\"&lt;BR /&gt;),&lt;BR /&gt;&amp;lt;&amp;lt;Set Show Hidden( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Subfolders( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Name Filter( "*.csv" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Name Enable( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Size Filter( {522, 2096152} ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Size Enable( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Date Filter( {3715322235, 3718948571} ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Date Enable( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Add File Name Column( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Add File Size Column( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Add File Date Column( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Import Mode( "CSVData" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Charset( "Best Guess" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Stack Mode( "Table Per File" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV Has Headers( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV Allow Numeric( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV First Header Line( 2 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV Number Of Header Lines( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV First Data Line( 3 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOF Comma( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOF Tab( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOF Space( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOF Spaces( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOF Other( "" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOL CRLF( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOL CR( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOL LF( 1 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOL Semicolon( 0 ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV EOL Other( "" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV Quote( "\!"" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set CSV Escape( "" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set XML Method( "guess" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set XML Guess( "huge" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set XML Settings( XML Settings() ),&lt;BR /&gt;&amp;lt;&amp;lt;Set JSON Method( "guess" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set JSON Guess( "huge" ),&lt;BR /&gt;&amp;lt;&amp;lt;Set JSON Settings( JSON Settings() ),&lt;BR /&gt;&amp;lt;&amp;lt;Set Import Callback( Empty() )&lt;BR /&gt;) &amp;lt;&amp;lt; Import Data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this code, there is no formula for where column names and data start.&lt;/P&gt;&lt;P&gt;Then, I tried to update a value by using:&lt;/P&gt;&lt;P&gt;dt: subjid &amp;lt;&amp;lt;&lt;BR /&gt;:id1&amp;nbsp;&amp;lt;&amp;lt; Set Formula(&lt;BR /&gt;If( :id2&amp;nbsp;== "a001", :id1 == "b001")&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;result, values prior to "a001" in id1 column are deleted and id1 value of "a001" is not updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am stock in this phase and can't even think of next stage of saving files under different names in their respective folders. Any help/guidance is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:40:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/433910#M68371</guid>
      <dc:creator>Helal</dc:creator>
      <dc:date>2023-06-10T23:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple CSV Files from different folder, Update Value, and save CSV with different names</title>
      <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434096#M68386</link>
      <description>&lt;P&gt;I'm not sure what your JSL did:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt: subjid &amp;lt;&amp;lt; :id1 &amp;lt;&amp;lt; Set Formula( If( :id2 == "a001", :id1 == "b001") )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The &amp;lt;&amp;lt; "send" operator should only appear once, and the column you are adding the formula to should be the left-hand-side. Then in the if statement, there should be a condition, followed by a value for the true case, and another value for the false case. Something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column( "likes",
	"character",
	formula( If( 
		Is Missing( name ), // first test
			"unknown", // if first test is true
		name == "KATIE", // second test
			"cats", // if second test is true
			"dogs"  // if second test is false
		) 
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is intended to create a new formula column of cats or dogs depending on the value in column name. If name is blank (missing), "unknown".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if your goal is to overwrite an existing column(s) based on values of other columns, perhaps an explicit loop would be better than a formula column:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;foreachrow(dt,
	if(
		name == "DANNY", // a test with ==
			name = "Dani"; // an assignment with =
			sex = "F";
		, /* else if */ name == "ROBERT",
			name = "Roberta";
			sex = "F";
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;( &lt;LI-MESSAGE title="If Secrets" uid="39558" url="https://community.jmp.com/t5/Uncharted/If-Secrets/m-p/39558#U39558" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; might help understanding the commas and semicolons. ) That leaves rows unchanged, unless&amp;nbsp; the name matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice how the two examples are different:&lt;/P&gt;
&lt;P&gt;The first example must produce an answer in the if(...) that will be assigned to the formula's column. &lt;STRIKE&gt;If the column should be unchanged for that row, the formula's value must be the original value for the row.&lt;/STRIKE&gt;&amp;nbsp; Edit: sorry, that's wrong. Just make sure the formula column produces a value for every row.&lt;/P&gt;
&lt;P&gt;The second example only updates rows and columns it chooses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you plan to write out a CSV file (not save a JMP file), the formula expression you add to a column will not be saved (though the updated values from the formula will be.) I think you might want something more like the second example.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 14:38:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434096#M68386</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-11-08T14:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple CSV Files from different folder, Update Value, and save CSV with different names</title>
      <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434195#M68399</link>
      <description>&lt;P&gt;Thank you Craige. As you mentioned, the second example worked well. However, it only worked if I open or import one csv but didn't work when I imported multiple CSVs. Also, will you please guide me to also accomplish the last stage of writing csv back to their respective folders with different filenames?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Helal&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 17:31:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434195#M68399</guid>
      <dc:creator>Helal</dc:creator>
      <dc:date>2021-11-08T17:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple CSV Files from different folder, Update Value, and save CSV with different names</title>
      <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434372#M68416</link>
      <description>&lt;P&gt;Thanks, made a post for it because it seems generally useful and some of it isn't really obvious how to do.&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="MFI Update CSV" uid="434365" url="https://community.jmp.com/t5/Uncharted/MFI-Update-CSV/m-p/434365#U434365" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 00:54:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/434372#M68416</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-11-09T00:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Import Multiple CSV Files from different folder, Update Value, and save CSV with different names</title>
      <link>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/435894#M68499</link>
      <description>&lt;P&gt;Thank you again. This is awesome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Helal&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 13:51:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Import-Multiple-CSV-Files-from-different-folder-Update-Value-and/m-p/435894#M68499</guid>
      <dc:creator>Helal</dc:creator>
      <dc:date>2021-11-12T13:51:18Z</dc:date>
    </item>
  </channel>
</rss>

