<?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 JSL Sum changing columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379518#M62947</link>
    <description>&lt;P&gt;Hello, if I have a table that changes once in a while something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="itzikd_0-1619353746140.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32326i836D104B40E003CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="itzikd_0-1619353746140.png" alt="itzikd_0-1619353746140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but another day it can be something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="itzikd_1-1619353780736.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32327iF1BBE6EAC18661DD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="itzikd_1-1619353780736.png" alt="itzikd_1-1619353780736.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I want to somehow create a new row that will sum all the columns except for Date and Data&lt;/P&gt;&lt;P&gt;what is the best way to do this in JSL?&lt;/P&gt;&lt;P&gt;I tried taking the columns names and then removing data and date but then I'm not sure how to do the sum part for each column&lt;/P&gt;&lt;P&gt;I tried using summary but each time it changes, once it will be sum of a,b,r,x and once a,c,f so I'm not sure this is possible..&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Summary(
	Sum( :A ),
	Sum( :B ),
	Sum( :R ),
	Sum( :X ),
	Freq( "None" ),
	Weight( "None" )
)

Summary(
	Sum( :A ),
	Sum( :C ),
	Sum( :F ),
	Freq( "None" ),
	Weight( "None" )
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Jun 2023 19:45:10 GMT</pubDate>
    <dc:creator>itzikd</dc:creator>
    <dc:date>2023-06-09T19:45:10Z</dc:date>
    <item>
      <title>JSL Sum changing columns</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379518#M62947</link>
      <description>&lt;P&gt;Hello, if I have a table that changes once in a while something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="itzikd_0-1619353746140.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32326i836D104B40E003CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="itzikd_0-1619353746140.png" alt="itzikd_0-1619353746140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but another day it can be something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="itzikd_1-1619353780736.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32327iF1BBE6EAC18661DD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="itzikd_1-1619353780736.png" alt="itzikd_1-1619353780736.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I want to somehow create a new row that will sum all the columns except for Date and Data&lt;/P&gt;&lt;P&gt;what is the best way to do this in JSL?&lt;/P&gt;&lt;P&gt;I tried taking the columns names and then removing data and date but then I'm not sure how to do the sum part for each column&lt;/P&gt;&lt;P&gt;I tried using summary but each time it changes, once it will be sum of a,b,r,x and once a,c,f so I'm not sure this is possible..&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Summary(
	Sum( :A ),
	Sum( :B ),
	Sum( :R ),
	Sum( :X ),
	Freq( "None" ),
	Weight( "None" )
)

Summary(
	Sum( :A ),
	Sum( :C ),
	Sum( :F ),
	Freq( "None" ),
	Weight( "None" )
)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:45:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379518#M62947</guid>
      <dc:creator>itzikd</dc:creator>
      <dc:date>2023-06-09T19:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Sum changing columns</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379527#M62948</link>
      <description>&lt;P&gt;Maybe you could use similar idea as here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/JMP-script-How-to-create-summary-of-a-bunch-of-cols-without/m-p/35398/highlight/true#M20892" target="_blank" rel="noopener"&gt;How to create summary of a bunch of cols without specifying column names?&lt;/A&gt;&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);
dt1 = New Table("Untitled1",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
	New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
	New Column("f", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7]))
);
colname = dt1 &amp;lt;&amp;lt; get column names(string);
colname = Substr(colname, 3); //remove data and date columns from list
summary_dt1 = dt1 &amp;lt;&amp;lt; Summary(Sum(Eval(colname)), Freq("None"), Weight("None"));
summary_dt1 &amp;lt;&amp;lt; Delete Columns("N Rows");

dt2 = New Table("Untitled2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
	New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
	New Column("r", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7])),
	New Column("x", Numeric, "Continuous", Format("Best", 12), Set Values([2, 7, 1]))
);
colname = dt2 &amp;lt;&amp;lt; get column names(string);
colname = Substr(colname, 3); //remove data and date columns from list
summary_dt2 = dt2 &amp;lt;&amp;lt; Summary(Sum(Eval(colname)), Freq("None"), Weight("None"));
summary_dt2 &amp;lt;&amp;lt; Delete Columns("N Rows");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Apr 2021 14:03:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379527#M62948</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-04-25T14:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Sum changing columns</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379538#M62950</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;has provided the correct answer.&amp;nbsp; I have a slight modification that I find very useful in many of the scripts that I write.&lt;/P&gt;
&lt;P&gt;I find that most of the time, the data tables that I get to work with, do not follow the same order of the columns from one access to lets say, the following weeks access.&amp;nbsp; Therefore, when I need to pair down a list of columns to be summarized etc. I use the following code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;colNamesNotToUse = {"DATA", "DATE"};
colname = dt &amp;lt;&amp;lt; get column names( string );

For( i = N Items( colName ), i &amp;gt;= 1, i--,
	If( Contains( colNamesNotToUse, Uppercase( colName[i] ) ),
		Remove From( colName, i, 1 )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Apr 2021 18:05:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/379538#M62950</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-25T18:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: JSL Sum changing columns</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/380191#M63046</link>
      <description>&lt;P&gt;Another way to do the same thing.&amp;nbsp; Not better, just different:&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);

dt1 = New Table("Untitled1",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
	New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
	New Column("f", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7]))
);

dt2 = New Table("Untitled2",
	Add Rows(3),
	Compress File When Saved(1),
	New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
	New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
	New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
	New Column("r", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7])),
	New Column("x", Numeric, "Continuous", Format("Best", 12), Set Values([2, 7, 1]))
);

//Put all in one table
dtConcat = dt1 &amp;lt;&amp;lt; Concatenate(
	dt2,
	Create source column
);

//Unpivot - one column with all values
dtStacked = dtConcat &amp;lt;&amp;lt; Stack(
	columns( 4::n col(dtConcat) ),
	Source Label Column( "Column" ),
	Stacked Data Column( "Value" )
);

//Use tabulate to find sums
dtSum = (tab = dtStacked &amp;lt;&amp;lt; Tabulate(
	Add Table(
		Column Table( Grouping Columns( :Column ), Analysis Columns( :Value ) )
	)
)) &amp;lt;&amp;lt; Make Into Data Table;

//Clean Up
tab &amp;lt;&amp;lt; Close Window;
dtStacked &amp;lt;&amp;lt; Close Window; dtConcat &amp;lt;&amp;lt; Close Window;
dt1 &amp;lt;&amp;lt; Close Window; dt2 &amp;lt;&amp;lt; Close Window;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Apr 2021 19:04:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Sum-changing-columns/m-p/380191#M63046</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-04-27T19:04:19Z</dc:date>
    </item>
  </channel>
</rss>

