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
- :
- Help with converting a SAS(9.1) iteration script i...

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

Jun 26, 2017 6:52 AM
(919 views)

Good day all.

I am having trouble with trying to convert some old SAS 9.1 code, that runs an ** iterative calculation** ("do until"), into JSL (I am running JMP 13).

Attached is the original SAS code as it appears in the JMP window when I open the *.SAS file. I have isolated the pertinent sub-section of the script from the original SAS script and attached it in *jsl format as "mg_in_olivine.jsl".

I have also included a dummy dataset with 29 records and a number of the required parameters have already been calculated (thre rest of the numerous columns have been hidden):

t_niK

PCr

dv

xmg_gt

xfe_gt

xca_gt

I would greatly appreciate any help I can get.

Many thanks.

Rob Preston (Johannesburg).

1 ACCEPTED SOLUTION

Accepted Solutions

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

Jun 26, 2017 7:28 AM
(1776 views)

Solution

Might this be what you are looking for?

```
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "xmg_ol_diff" );
For( i = 1, i <= N Rows( dt ), i++,
counter = 0;
While( Abs( dt:xmg_ol_diff[i] ) > 0.00001 | Is Missing( dt:xmg_ol_diff[i] ) == 1,
counter++;
If( counter > 100, Break() );
logKd = (902 + dt:dv[i] + (dt:xmg_ol_est[i] - dt:xfe_ol_est[i]) * (498 + 1.51 * (dt:PCr[i] - 30)) - 98 * (dt:xmg_gt[i] - dt:xfe_gt[i])
+1347 * dt:xca_gt[i]) / dt:t_niK[i] - 0.357;
Kd = Exp( LogKd );
xmgfe_ol = Kd * (dt:xmg_gt[i] / dt:xfe_gt[i]);
xmg_ol = xmgfe_ol / (1 + xmgfe_ol);
dt:xmg_ol_diff[i] = xmg_ol - dt:xmg_ol_est[i];
dt:xmg_ol_est[i] = xmg_ol; /** reset xmg_ol_est for next iteration **/
dt:xfe_ol_est[i] = 1.0 - xmg_ol;
);
);
```

Jim

8 REPLIES

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

Jun 26, 2017 7:06 AM
(915 views)

Look at the **While()** function for this kind of iteration.

- Help > Books > Scripting Guide

Learn it once, use it forever!

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

Jun 26, 2017 7:24 AM
(910 views)

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

Jun 26, 2017 7:28 AM
(1777 views)

Might this be what you are looking for?

```
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "xmg_ol_diff" );
For( i = 1, i <= N Rows( dt ), i++,
counter = 0;
While( Abs( dt:xmg_ol_diff[i] ) > 0.00001 | Is Missing( dt:xmg_ol_diff[i] ) == 1,
counter++;
If( counter > 100, Break() );
logKd = (902 + dt:dv[i] + (dt:xmg_ol_est[i] - dt:xfe_ol_est[i]) * (498 + 1.51 * (dt:PCr[i] - 30)) - 98 * (dt:xmg_gt[i] - dt:xfe_gt[i])
+1347 * dt:xca_gt[i]) / dt:t_niK[i] - 0.357;
Kd = Exp( LogKd );
xmgfe_ol = Kd * (dt:xmg_gt[i] / dt:xfe_gt[i]);
xmg_ol = xmgfe_ol / (1 + xmgfe_ol);
dt:xmg_ol_diff[i] = xmg_ol - dt:xmg_ol_est[i];
dt:xmg_ol_est[i] = xmg_ol; /** reset xmg_ol_est for next iteration **/
dt:xfe_ol_est[i] = 1.0 - xmg_ol;
);
);
```

Jim

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

Jun 26, 2017 7:41 AM
(904 views)

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

Jun 26, 2017 8:21 AM
(891 views)

The the end of the script, the final output value should be xmg_ol as ii is the input value for next section of code (as follows):

/** now apply Gaul et al correction for cr2o3 - see p. 225 **/

/** note that in Gaul et al Delta-Fo is in percent **/

/** make sure cr2o3 > 0 otherwise we get log ERROR **/

if cr2o3 <=0 then

cr_corr = 0;

else

cr_corr = (-1.2901*log10(cr2o3) + 0.69)/100.0;

xmg_ol_corr = xmg_ol + cr_corr;

xmg_ol = xmg_ol_corr;

fo_oliv = xmg_ol*100.0;

I am a bit clueless (to say the least)...but I appreciate your help.

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

Jun 26, 2017 9:21 AM
(888 views)

1. I encourage you to heed Mark's suggestion about reading the Scripting Guide. What you are asking for in your latest request is just learning what an "IF" statement looks like in JMP. Converting syntax from language to language is typically just figuring out some minor language issues.

2. You can also use the Scripting Index

Help==>Scripting Index

to see not only documentation on the "IF" statement, but also an example

Here is the example from the Scripting Index for the IF function. It will translate directly to you latest request.

```
Names Default To Here( 1 );
If( Random Uniform() < 0.5,
"heads",
"tails"
);
```

Jim

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

Jun 26, 2017 11:13 PM
(878 views)

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

Jun 27, 2017 12:27 AM
(876 views)

Thanks again for your help, I'm getting there albeit slowly.

:)