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

- JMP User Community
- :
- Discussions
- :
- I can't even do this simple replace!

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

Highlighted

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

Sep 3, 2018 3:36 AM
(5322 views)

5 ACCEPTED SOLUTIONS

Accepted Solutions

Highlighted

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

You could use data table subscripting:

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
maleRows = Loc(dt[0, "sex"], "M");
dt[maleRows, "sex"] = "boy";
```

Highlighted
I've tried to write JSL in a way that only works with perfectly matched substitutions, but if you don't want to replace only a few characters, how do you write JSL?Thank you!

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

Highlighted

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

Created:
Sep 3, 2018 7:04 AM
| Last Modified: Sep 3, 2018 7:06 AM
(5292 views)
| Posted in reply to message from lwx228 09-03-2018

This is one way to do it

```
dt = Current Data Table();
dt:class[dt << get rows where( dt:class == "A1" )] = "A9";
```

Jim

Highlighted

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

OK. So maybe take a look at regular expressions.

Highlighted

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

That is not all the ways it can be coded in JSL to accomplish what you want, but Ian's suggestion is what I would have also suggested as the solution.

Jim

14 REPLIES 14

Highlighted

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

You could use data table subscripting:

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
maleRows = Loc(dt[0, "sex"], "M");
dt[maleRows, "sex"] = "boy";
```

Highlighted
##

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

Re: I can't even do this simple replace!

It seems to be quite different from the VBA approach.thank you!

Highlighted
I've tried to write JSL in a way that only works with perfectly matched substitutions, but if you don't want to replace only a few characters, how do you write JSL?Thank you!

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

Highlighted

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

Created:
Sep 3, 2018 7:04 AM
| Last Modified: Sep 3, 2018 7:06 AM
(5293 views)
| Posted in reply to message from lwx228 09-03-2018

This is one way to do it

```
dt = Current Data Table();
dt:class[dt << get rows where( dt:class == "A1" )] = "A9";
```

Jim

Highlighted
##

If this is the new case, this JSL is not very efficient.Can the code be improved for the new instance?Thank you!

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

Re: I can't even do this simple replace!

Highlighted
##

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

Re: I can't even do this simple replace!

If I understand correctly, consider using the 'Match()' JSL expression. I generated the code below by using 'Cols > Recode':

and inspecting the JSL for the resulting formula column. And, 'yes', JSL is very different from VBA. You should look at 'Help > Books > Scripting Guide' and/or consider some training.

```
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
dt << New Column( "Age 2",
Character,
"Ordinal",
Formula(
Match( :age,
12, "Twelve",
13, "Thirteen",
14, "Fourteen",
15, "Fifteen",
16, "Sixteen",
17, "Seventeen",
Format( :age, "Fixed Dec", 5, 0 )
)
)
);
```

Highlighted
##

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

Re: I can't even do this simple replace!

I'm so sorry!Maybe the example I gave is not appropriate and misleading.

I just want to replace some of the specified characters with others in the same column.That is the manual interface function, just want to use JSL implementation.

The VBA implementation in excel is simple:Selection.Replace What:="1", Replacement:="9", LookAt:=xlPart

I just want the effect of this simple trade effect.But I don't have the corresponding code in JSL.Thank you!

I just want to replace some of the specified characters with others in the same column.That is the manual interface function, just want to use JSL implementation.

The VBA implementation in excel is simple:Selection.Replace What:="1", Replacement:="9", LookAt:=xlPart

I just want the effect of this simple trade effect.But I don't have the corresponding code in JSL.Thank you!

Highlighted
##

This is the result of the substitution in the case of "Match entire cell value" the multiple checkbox is not selected.Thank you!

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

Re: I can't even do this simple replace!

Highlighted
##

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

Re: I can't even do this simple replace!

It's just a matter of replacing some characters in a cell with JSL.

Article Labels

There are no labels assigned to this post.