BookmarkSubscribe
Choose Language Hide Translation Bar
Community Trekker

## adding two columns and doing sum in JSL

i have an excel sheet with the following rows and columns:

 Numbers Red Blue Black Green 7006 1 0 1 2 7009 1 2 3 4 7012 1 4 5 6 7015 1 6 7 8 7018 1 8 9 10 7021 1 10 11 12 7024 1 12 13 14 7027 1 14 15 16 7030 1 16 17 18 7033 1 18 19 20 7036 1 20 21 22 7039 1 22 23 24

now i need to add two columns namely red+blue and black+green  and count the total of red+blue for each number and place in the resultant column..and same with the second column too..my result should be

 Numbers Red Blue Black Green red+blue black+green 7006 1 0 1 2 1 3 7009 1 2 3 4 3 7 7012 1 4 5 6 5 11 7015 1 6 7 8 7 15 7018 1 8 9 10 9 19 7021 1 10 11 12 11 23 7024 1 12 13 14 13 27 7027 1 14 15 16 15 31 7030 1 16 17 18 17 35 7033 1 18 19 20 19 39 7036 1 20 21 22 21 43 7039 1 22 23 24 23 47

can some one help me with the code?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User

## Re: adding two columns and doing sum in JSL

Assuming you know how to import (or just paste) your table into JMP, it is pretty straight-forward. The example below illustrates two approaches 1) static columns and 2) column formulas. The latter will update the sum if values are changed, the former will not.

//Make example table

dt=New Table( "Colors",

New Column( "Numbers",

Numeric,

Continuous,

Format( "Best", 4 ),

Set Selected,

Set Values( [7006, 7009, 7012] )

),

New Column( "Red",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [1, 1, 1] )

),

New Column( "Blue",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [0, 2, 4] )

),

New Column( "Black",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [1, 3, 5] )

),

New Column( "Green",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [2, 4, 6] )

)

);

//Alternative 1: static columns

dt<<new column("Red+Blue", continious);

dt<<new column("Black+Green", continious);

for each row(:Name("Red+Blue")=:Red+:Blue);

for each row(:Name("Black+Green")=:Black+:Green);

//Alternative 2: Column formulas

dt<<new column("Red+Blue2", continious, Formula(:Red+:Blue));

dt<<new column("Black+Green2", continious, Formula(:Black+:Green));

Highlighted
Super User

## Re: adding two columns and doing sum in JSL

Assuming you know how to import (or just paste) your table into JMP, it is pretty straight-forward. The example below illustrates two approaches 1) static columns and 2) column formulas. The latter will update the sum if values are changed, the former will not.

//Make example table

dt=New Table( "Colors",

New Column( "Numbers",

Numeric,

Continuous,

Format( "Best", 4 ),

Set Selected,

Set Values( [7006, 7009, 7012] )

),

New Column( "Red",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [1, 1, 1] )

),

New Column( "Blue",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [0, 2, 4] )

),

New Column( "Black",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [1, 3, 5] )

),

New Column( "Green",

Numeric,

Continuous,

Format( "Best", 12 ),

Set Selected,

Set Values( [2, 4, 6] )

)

);

//Alternative 1: static columns

dt<<new column("Red+Blue", continious);

dt<<new column("Black+Green", continious);

for each row(:Name("Red+Blue")=:Red+:Blue);

for each row(:Name("Black+Green")=:Black+:Green);

//Alternative 2: Column formulas

dt<<new column("Red+Blue2", continious, Formula(:Red+:Blue));

dt<<new column("Black+Green2", continious, Formula(:Black+:Green));