BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar

Community Trekker

Joined:

Aug 3, 2016

## Help with converting a SAS(9.1) iteration script into JSL...?

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

Super User

Joined:

Jun 22, 2012

Solution

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

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 8

Staff

Joined:

Jun 23, 2011

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

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

• Help > Books > Scripting Guide
Learn it once, use it forever!

Community Trekker

Joined:

Aug 3, 2016

Thanks Mark.

Super User

Joined:

Jun 22, 2012

Solution

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

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

Community Trekker

Joined:

Aug 3, 2016

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

Hi Jim. Thanks very much for responding.

Just checking...

Highlighted

Community Trekker

Joined:

Aug 3, 2016

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

Hi again Jim.
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.

Super User

Joined:

Jun 22, 2012

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

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

Community Trekker

Joined:

Aug 3, 2016

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

Thanks very much for your assistance Jim.

Community Trekker

Joined:

Aug 3, 2016

## Re: Help with converting a SAS(9.1) iteration script into JSL...?

Think I've got it - i didnt have a problem with the simple IF statement, it was just the iteration.
Thanks again for your help, I'm getting there albeit slowly.
:)