<?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: Delete cell values based on a column condition and merge rows with same timestamp using JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Delete-cell-values-based-on-a-column-condition-and-merge-rows/m-p/251905#M49465</link>
    <description>&lt;P&gt;This should do it for you, but the script assumes that the status columns correspond to the column just preceding them.&amp;nbsp; You could do this by looking at the name of the status column and finding a column with the same name minus " Status", but I figured that is unnecessarily complicated if the assumption is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
col_names = dt &amp;lt;&amp;lt; Get Column Names(string);

//Assuming the corresponding value column for each status column is always the preceding one
//Loop backwards through the columns
for(i = N Col(dt), i&amp;gt;= 1, i--,
	//If column name has word "status" in it
	if(Contains(Lowercase(col_names[i]), "status") &amp;gt; 0, 
		//Look for instances of "{down}"
		down_rows = dt &amp;lt;&amp;lt; Get Rows Where( dt:(As Name(col_names[i])) == "{down}" );
		//Assuming preceding column is the value column, replace {down} rows with missing
		Column(dt, i-1)[down_rows] = .;
		dt &amp;lt;&amp;lt; Delete Columns(i);
	);
);


//Create table summary to consolidate time stamp rows with same value
//Build a string that we can parse for the summary operation
remaining_cols = dt &amp;lt;&amp;lt; Get Column Names("string");
summary_str = "dt_clean = dt &amp;lt;&amp;lt; Summary( Group( :TimeStamp ), ";

//Loop through all columns except TimeStamp to add "Sum( &amp;lt;current col&amp;gt; )" to summary string
for(i = 2, i &amp;lt;= N Col(dt), i++,
	summary_str = summary_str||"Sum( :Name(\!""||remaining_cols[i]||"\!")), ";
);

//Attach last part of script
summary_str = summary_str||"Freq( \!"None\!"), 
Weight(\!"None\!"), 
statistics column name format( \!"column\!" ),
Link to original data table( 0 ),
output table name( \!"CleanedData\!" ));";

//Parse and evaluate the string to create the summary table dt_new
eval(parse(summary_str));

//Delete N Rows column
dt_clean &amp;lt;&amp;lt; Delete Columns(:N Rows);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Mar 2020 23:11:13 GMT</pubDate>
    <dc:creator>cwillden</dc:creator>
    <dc:date>2020-03-11T23:11:13Z</dc:date>
    <item>
      <title>Delete cell values based on a column condition and merge rows with same timestamp using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Delete-cell-values-based-on-a-column-condition-and-merge-rows/m-p/251788#M49447</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have following "TestData":&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="himajamuppalla_0-1583940231432.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22291i2796845B16B9D884/image-size/medium?v=v2&amp;amp;px=400" role="button" title="himajamuppalla_0-1583940231432.png" alt="himajamuppalla_0-1583940231432.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;1. I want the cell value to be null when the status is down. for example ("A status " cell value is "down" the value in Column "A" should be null instead of "1334". should do the same for B , C and D Columns.&lt;/P&gt;&lt;P&gt;2.Delete all the columns that has "status" in the column name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should be something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="himajamuppalla_1-1583940469851.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22292i9523534325BBD06C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="himajamuppalla_1-1583940469851.png" alt="himajamuppalla_1-1583940469851.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="himajamuppalla_2-1583940499788.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22293iD7B3FE42F88310EB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="himajamuppalla_2-1583940499788.png" alt="himajamuppalla_2-1583940499788.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;3. Now all the same timestamp rows&amp;nbsp; should be merged. expected output would be:(i know i can use summary [group by and sum] to achieve this . But is there a better way to do it in JSL?)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="himajamuppalla_3-1583940682171.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/22294i37A2A7707A2EDF9A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="himajamuppalla_3-1583940682171.png" alt="himajamuppalla_3-1583940682171.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to do this for multiple csv files. Can someone help me out writing JSL for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advnace.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:26:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Delete-cell-values-based-on-a-column-condition-and-merge-rows/m-p/251788#M49447</guid>
      <dc:creator>himajamuppalla</dc:creator>
      <dc:date>2023-06-09T23:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Delete cell values based on a column condition and merge rows with same timestamp using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Delete-cell-values-based-on-a-column-condition-and-merge-rows/m-p/251905#M49465</link>
      <description>&lt;P&gt;This should do it for you, but the script assumes that the status columns correspond to the column just preceding them.&amp;nbsp; You could do this by looking at the name of the status column and finding a column with the same name minus " Status", but I figured that is unnecessarily complicated if the assumption is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
col_names = dt &amp;lt;&amp;lt; Get Column Names(string);

//Assuming the corresponding value column for each status column is always the preceding one
//Loop backwards through the columns
for(i = N Col(dt), i&amp;gt;= 1, i--,
	//If column name has word "status" in it
	if(Contains(Lowercase(col_names[i]), "status") &amp;gt; 0, 
		//Look for instances of "{down}"
		down_rows = dt &amp;lt;&amp;lt; Get Rows Where( dt:(As Name(col_names[i])) == "{down}" );
		//Assuming preceding column is the value column, replace {down} rows with missing
		Column(dt, i-1)[down_rows] = .;
		dt &amp;lt;&amp;lt; Delete Columns(i);
	);
);


//Create table summary to consolidate time stamp rows with same value
//Build a string that we can parse for the summary operation
remaining_cols = dt &amp;lt;&amp;lt; Get Column Names("string");
summary_str = "dt_clean = dt &amp;lt;&amp;lt; Summary( Group( :TimeStamp ), ";

//Loop through all columns except TimeStamp to add "Sum( &amp;lt;current col&amp;gt; )" to summary string
for(i = 2, i &amp;lt;= N Col(dt), i++,
	summary_str = summary_str||"Sum( :Name(\!""||remaining_cols[i]||"\!")), ";
);

//Attach last part of script
summary_str = summary_str||"Freq( \!"None\!"), 
Weight(\!"None\!"), 
statistics column name format( \!"column\!" ),
Link to original data table( 0 ),
output table name( \!"CleanedData\!" ));";

//Parse and evaluate the string to create the summary table dt_new
eval(parse(summary_str));

//Delete N Rows column
dt_clean &amp;lt;&amp;lt; Delete Columns(:N Rows);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Mar 2020 23:11:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Delete-cell-values-based-on-a-column-condition-and-merge-rows/m-p/251905#M49465</guid>
      <dc:creator>cwillden</dc:creator>
      <dc:date>2020-03-11T23:11:13Z</dc:date>
    </item>
  </channel>
</rss>

