Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Delete rows based upon condition

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 21, 2018 3:17 PM
(906 views)

Hi,

I would like to use for loop to delete my columns. Below is an example but I have more columsn.

Also, how you treat columns with white space in between like "color size".

Thanks.

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
column_list = Words( "heigth", "weight" );
For( i = N Items( column_list ), i > 0, i--,
dt << Select Where( :column_list[i] > 67 );
dt << delete rows;
);

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

I am not sure what you are actually asking for. Therefore, I am including 2 different scripts. The first one deletes all of the rows that meet your condition of values > 67. When you delete rows, it deletes the entire row, so the results of this script deletes all but 2 rows.

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
column_list = {"height", "weight"};
For( i = N Items( column_list ), i > 0, i--,
dt << Select Where( as column(column_list[i]) > 67 );
dt << delete rows;
);
```

But what I think you might be trying to do, is to eliminate the values in the columns where the value of height and weight are > 67. This script replaces the values of height and weight with missing values.

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
column_list = {"height", "weight"};
For( i = N Items( column_list ), i > 0, i--,
SelectedRows = dt << get rows Where( as column(column_list[i]) > 67 );
column(column_List[i])[Selected Rows] = .;
);
```

Jim

1 REPLY 1

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

I am not sure what you are actually asking for. Therefore, I am including 2 different scripts. The first one deletes all of the rows that meet your condition of values > 67. When you delete rows, it deletes the entire row, so the results of this script deletes all but 2 rows.

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
column_list = {"height", "weight"};
For( i = N Items( column_list ), i > 0, i--,
dt << Select Where( as column(column_list[i]) > 67 );
dt << delete rows;
);
```

But what I think you might be trying to do, is to eliminate the values in the columns where the value of height and weight are > 67. This script replaces the values of height and weight with missing values.

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
column_list = {"height", "weight"};
For( i = N Items( column_list ), i > 0, i--,
SelectedRows = dt << get rows Where( as column(column_list[i]) > 67 );
column(column_List[i])[Selected Rows] = .;
);
```

Jim