cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
dfmoore
Level II

Sum all Columns that contain a string in the column name

I'm trying to take a data table and add a column with a formula that sums all columns that contain the string "ToAdd" in the column name. I'm trying to script this because the columns that will have "ToAdd" somewhere in the name will change.

So far, I have the script that can collect all the column names into a list, but I'm not sure how to then use that list to generate a new column with a formula that sums all those columns together. This seemed like the best way to start, but not sure where to go from here (or if it really is a good way to start)

dt = current data table();

N = N Col( dt );

AddColumns = {};

For( i=1, i <= N, i++,

    colname = Column(i) << getname();

    If( Contains( colname, "ToAdd") > 1,

        Insert Into(AddColumns, colname )

    );

    )

);

Thanks for any help in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Sum all Columns that contain a string in the column name

It's a good start. To set column formulas by script, however, is a bit tricky as the argument is interpreted literally. Building a formula dynamically usually involves building strings or expressions that finally is parsed/evaluated. Otherwise local or session-specific variables will end up in the formula and it will not work as expected. At least that is my experience.

Here's an example using the string approach:

dt = Current Data Table();

N = N Col( dt );

s = "";

For( i = 1, i <= N, i++,

  colname = Column( i ) << getname();

  If( Contains( colname, "ToAdd" ) > 0,

  s = s || If( Length( s ) > 0, ", ", "" ) || colname

  );

);

show(s);

col = dt << New Column( "Sum(AddColumns)", numeric );

Eval( Parse( Eval Insert( "col<<set formula(sum(^s^))" ) ) );

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Sum all Columns that contain a string in the column name

It's a good start. To set column formulas by script, however, is a bit tricky as the argument is interpreted literally. Building a formula dynamically usually involves building strings or expressions that finally is parsed/evaluated. Otherwise local or session-specific variables will end up in the formula and it will not work as expected. At least that is my experience.

Here's an example using the string approach:

dt = Current Data Table();

N = N Col( dt );

s = "";

For( i = 1, i <= N, i++,

  colname = Column( i ) << getname();

  If( Contains( colname, "ToAdd" ) > 0,

  s = s || If( Length( s ) > 0, ", ", "" ) || colname

  );

);

show(s);

col = dt << New Column( "Sum(AddColumns)", numeric );

Eval( Parse( Eval Insert( "col<<set formula(sum(^s^))" ) ) );

dfmoore
Level II

Re: Sum all Columns that contain a string in the column name

Works like a charm!

Thanks,

Daniel

Recommended Articles