cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

How can I find the row and column of a value within a data table?

Hi all,

I need to find the column and row number of a particular value within a data table.   I know how to search for a value within a particular column (ie., row = dt1 << get rows where(:Device == "Device");) , which returns the row number, but what if I don't know what row it will be in?

Is it possible to do this in JMP?  I see how to do it from going to edit then search, but is there a way to do this in JSL?

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: How can I find the row and column of a value within a data table?

If you're looking for text, then this example may be helpful:

dt = open("$sample_data\Bands Data.jmp");

char_cols = dt << get column names(Character, string);

search_string = "E310";

for (i = 1, i <= nitems(char_cols), i++,

    match_rows = dt << get rows where(as column(dt, char_cols[i]) == search_string);

    if (nrows(match_rows) > 0,

        print("Column: [" || char_cols[i] || "] Rows: " || char(match_rows));

    );

);

View solution in original post

2 REPLIES 2
pmroz
Super User

Re: How can I find the row and column of a value within a data table?

If you're looking for text, then this example may be helpful:

dt = open("$sample_data\Bands Data.jmp");

char_cols = dt << get column names(Character, string);

search_string = "E310";

for (i = 1, i <= nitems(char_cols), i++,

    match_rows = dt << get rows where(as column(dt, char_cols[i]) == search_string);

    if (nrows(match_rows) > 0,

        print("Column: [" || char_cols[i] || "] Rows: " || char(match_rows));

    );

);

natalie_
Level V

Re: How can I find the row and column of a value within a data table?

Thank you, your examples are always great!

I know that the value can only happen once in the file, so I made a while loop instead so that it would not continue to check the other columns for it.

file = Pick File();

dt = Open (file);

for(i=1, i<=ncols(dt), i++,

  column(dt,i) << data type(Character);

  column(dt,i) << set modeling type(continuous);

);

nCols = dt << Get Column Names ("Character");

found =0;

search_string = "Vtlin";

i=1;

While (found == 0,

  match_rows = dt << get rows where(as column(dt, nCols)==search_string);

  if(nrows(match_rows) > 0, found = 1, i++);

  if(i==nCols, found =1, );

);

vtlinCol = i;

Recommended Articles