Subscribe Bookmark RSS Feed

Concatenate subset, within a loop

awalts12

Community Trekker

Joined:

Dec 21, 2015

I have a loop during each iteration of which I select a subset of rows.

I'm trying to concatenate those rows and then, after exiting the loop, show the list of rows selected during each loop in one list.

Basically what I have is:

cohort ={xxx, yyy, zzz};

for (i=1, i<= N items (cohort), i++,

     dt << Select Where( starts with( :subject, cohort );

     subCohort = dt << Subset( output table name( "test" ), Selected Rows( 50 ), invisible );

     freezerlist = concatenate (subCohort);

);

show(freezerlist);

From the above I get an individual window with the subset table "test" for each iteration but I can't get them to join together in one list.

Thanks for any help.

Avram

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Building a little of msharp's response, maybe this is what you're looking for:

new = New Table( "FreezerList" );  // Make an empty table;

cohort = {xxx, yyy, zzz};

For( i = 1, i <= N Items( cohort ), i++,

    dt << Select Where( Starts With( :subject, cohort ), current selection( "extend" ) );

    subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

    new<< Concatenate( subCohort, Append to First Table );

    Close( subCohort, NoSave );

);

5 REPLIES
msharp

Super User

Joined:

Jul 28, 2015

This is confusing, I'm not really sure what you are trying to do. (freezerlist = concatenate(subCohort)) doesn't make sense, and I can't make heads or tails since I don't know what freezerlist is.  I'm guessing it's suppose to be a data table.

Are you looping through, creating subsets, and then trying to concatenate those subsets?  In which case I want to know why you don't just do it all at once and only make one subset?

cohort ={xxx, yyy, zzz};

for (i=1, i<= N items (cohort), i++,

    dt << Select Where( starts with(:subject, cohort[i]), current selection("extend"));

);

subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

freezerlist = dt << Get Selected Columns;

show(freezerlist);


Note: you can concatenate strings, lists, matrices, and data tables.

  Concat(string1, string2);

  Concat(matrix1, matrix2);

  datatable1 << Concatenate( datatable2 );



awalts12

Community Trekker

Joined:

Dec 21, 2015

Sorry ...

In words what i am trying to do is use a loop to read through a long table for a rows searching for a certain prefix (that changes on each loop) and several other criteria (that are static).

On each pass through the loop, certain rows are identified.

The prefix being searched for changes with each iteration but the other criteria remain the same.

What I want is to create a single list (called freezerlist) containing the rows identified in each loop.

Thanks

txnelson

Super User

Joined:

Jun 22, 2012

Here is a working piece of code that I believe may be close to what you want......I am making the assumption you what the actual data from the selected rows, and not the row numbers.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

// Change the column name "name" to "subject"" to match the example

dt:name << set name( "subject" );

cohort = {"C", "J", "S"};

dt << Select Where( Starts With( :subject, cohort[1] ) );

baseDT = dt << Subset( output table name( "Test" ), selected rows( 1 ), selected columns( 0 ) );

For( i = 2, i <= N Items( cohort ), i++,

dt << Select Where( Starts With( :subject, cohort ) );

TempDT = dt << Subset( output table name( "Test" ), selected rows( 1 ), selected columns( 0 ) );

baseDT = baseDT << concatenate( TempDT, append to first table( 1 ) );

Close( TempDT, nosave );

);

freezerlist = baseDT:subject<<get values;

show(freezerlist);

Jim
Solution

Building a little of msharp's response, maybe this is what you're looking for:

new = New Table( "FreezerList" );  // Make an empty table;

cohort = {xxx, yyy, zzz};

For( i = 1, i <= N Items( cohort ), i++,

    dt << Select Where( Starts With( :subject, cohort ), current selection( "extend" ) );

    subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

    new<< Concatenate( subCohort, Append to First Table );

    Close( subCohort, NoSave );

);

awalts12

Community Trekker

Joined:

Dec 21, 2015

Thanks - this works nicely!