sumif: count columns if they contain some characterHello,
I found a discussion from 2015 (subject "sumif") that has a very helpful script for my current task.I wrote there my question but I don't know if people who participated in that discussion can see my question.
This script I found (slightly modified) and it works great for counting columns for each row where values are "0/0" (or whatever).
dt << New Column("Sum",
Numeric, Formula(
Local({i = 0, n = N Col(Current Data Table()) - 1},
Sum(Repeat({i++ ; (Column(i)[] =="0/0")}, n))
)
)
);However, how to edit this script to count columns that Contain "some_character"?
I have attached a data table where the last column "Sum" has a formula and needed resulted numbers.
I have a big data table and would like to have a script for counting columns for each row with specific values (as character).
I tried to modify the script above but it doesn't work:
dt << New Column("Miss",
Numeric, Formula(
Local({i = 0, n = N Col(Current Data Table()) - 1},
Sum(Repeat({i++ ; (Contains(Column(i)[],"."))}, n))
)
)
);</CODE>Please, help</P><P>Valentina</P></LINGO-BODY><LINGO-LABS id="lingo-labs-737490" slang="en-US" mode="CREATE"><LINGO-LABEL>Automation and Scripting</LINGO-LABEL></LINGO-LABS><LINGO-SUB id="lingo-sub-737586" slang="en-US" mode="CREATE">Re: sumif: count columns if they contain some character</LINGO-SUB><LINGO-BODY id="lingo-body-737586" slang="en-US" mode="CREATE"><P>The original data table you attached wasn't like that as it has 4 columns (you cannot ignore Sum column)</P>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1711103084651.png" style="width: 400px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_0-1711103084651.png" style="width: 400px;"><img src="https://us.v-cdn.net/6038925/uploads/images/62510iAAF3B35AD80E493A/jthi_0-1711103084651.png" role="button" title="jthi_0-1711103084651.png" alt="jthi_0-1711103084651.png" /></span></SPAN></P>
<P>Depending on your data, this is how I would do this if I were to use a Formula (most likely I would avoid that and just use a pure script solution)</P>
<PRE><CODE class=" language-jsl">Names Default To Here(1);
dt = Open("$DOWNLOADS/sum_help_data.jmp");
dt << Delete Column("Sum");
dt << New Column("Miss", Numeric, Continuous, Formula(
As Constant(
cols_of_interest = Filter Each({colname}, Current Data Table() << Get Column Names("String"),
!IsMissing(Regex(colname, "S\d"));
);
);
Local({
res = 0;
},
For Each({colname}, cols_of_interest,
res = res + (Contains(Column(colname)[], ".") > 0);
);
res;
);
));
Re: sumif: count columns if they contain some characterYes, it seems all data should be the same type.
Thank you - it works!
Re: sumif: count columns if they contain some characterI have attached a small data table to my post. It has 3 rows and 3 cols with a header:
S1 S2 S3
0/0 ./. 0/0
./. ./. ./.
0/0 0/0 0/0
The script doesn't work in this sample table
Column sum Formula Interrupted
argument is wrong type at row 1 in access or evaluation of 'Contains' , Bad Argument( Column( i )[] ), Contains/*###*/(Column( i )[], ".")
Formula evaluation errors have been ignored
Re: sumif: count columns if they contain some characterMost likely your loop is reaching some column which isn't character column. This part most likely needs some modification
n = N Col(Current Data Table()) - 1
how it should be done is very difficult to know without any knowledge of your data. It could be just a simple modification to the -1, getting list of character columns or calculating which columns to go through by some sort of a pattern
Re: sumif: count columns if they contain some characterThis is from my log:
Column Sum Formula Interrupted
argument is wrong type at row 421001 in access or evaluation of 'Contains' , Bad Argument( Column( i )[] ), Contains/*###*/(Column( i )[], ".")
Formula evaluation errors have been ignored
Re: sumif: count columns if they contain some characterSorry, I don't understand your question.
I have a table ~500,000 rows and ~3,000 columns. I need to calculate Sum across columns that contain a dot - cant use formula. .
I want to have a script, any script that would work. I tried different approaches but none worked. .
Re: sumif: count columns if they contain some characterDo you need to have a formula for this?