SAS to JSL - Do Loops...I am a long time SAS user being forced to learn JSL...
Things I found easy in SAS seem so difficult in JSL...
Could someone show me how Do Loops work in JSL by sharing with me JSL code that would generate the following nested do loop table using JSL?
data frustration;
do temp = 1 to 10 by 1;
do press = 5 to 20 by 5;
do time = 1 to 1000 by 20;
output;
end;
end;
end;
run;
This should be fairly simple to create these types of simulations but I can't seem to figure this out.
ScriptingRe: SAS to JSL - Do Loops...Jeff - so sorry to be late to this. You went above and beyond with this reply and I thank you. Reason I haven't checked back is because I was able to get it to work as I wanted. Thanks very much for the explanation of JSL and SAS differences. It was really helpful
Re: SAS to JSL - Do Loops...Hi @fat_angus, welcome to being a JMP user and to the JMP User Community.
As a longtime SAS programmer (I am one myself) you'll need to think about JMP and JSL very differently from the way you think about SAS.
For example, you posted a question about a SAS DATA step. As you know, the DATA step is all about creating a SAS data set. There is no direct equivalent for the DATA step in JSL since JSL is mostly about automating the things you would do interactively in JMP.
For that reason, I always encourage people to make sure they have a good foundation in using JMP interactively before they begin thinking about what tasks they wan to automate.
For example, to create the data table you create in your DATA step, I would create a File->New Table...
Then Cols->New Columns... to add a new column and give it a formula using the Sequence() function.

Temp columnTemp columnTemp column
I'd do the same for the other columns.
press columnpress columnpress column
â
time columntime columntime column
After adding rows to the data table you'll end up with this:

When you're ready you can go to the red triangle next to the data table's name and Copy Table Script.

That will give you the following script to create a New Table:
New Table( "untitled",
Add Rows( 2000 ),
New Column( "temp",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 1, 10, 1, 200 ) )
),
New Column( "press",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 5, 20, 5, 50 ) )
),
New Column( "time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Sequence( 1, 1000, 20 ) ),
)
)
There are, of course, other interactive ways to get the table you've described in your DATA step. You could create three tables with your sequences and then use Tables->Join and a couple of Cartesian Joins to get the same table. When you're ready JMP can give you the scripts for those steps along the way.
Regardless, it all starts with understanding how to use JMP and especially data tables interactively before you think about scripting it. After all, you don't know what's necessary to script until you know what JMP can with built-in tools already.
Keep learning and keep asking questions here in the Community. We're happy to help!
Re: SAS to JSL - Do Loops...This is great Craige_HALES!
I very much appreciate you taking time to explain.
Re: SAS to JSL - Do Loops...Thanks SUPER USER PMROZ once again; this is helpful.
Re: SAS to JSL - Do Loops...A complete example, appreciating how hard it is to get started in a new language. (The help->scripting index and the online help are complementary resources. I mostly use the help->scripting index, for reminding me how it works. The online help might be better for starting out.) I put a little more here than just needed. I've forgotten SAS rules for case of names...
Names Default To Here( 1 );
// what does that mean? JSL has several namespaces; the 'here' namespace is for this
// editor window and means 'press' is really 'here:press' but 'dtFrustration:press' belongs to
// the table's namespace (of column names.) You could also just use different names,
// like 'iPress' for the loop control variable. JMP's variable names are almost never
// case sensitive, the weird exception being column names, which are only sensitive <BR />// if both 'Age' and 'age' are columns...Don't do that!
// an easy way to get this table script is to make a new table with the
// JMP GUI, then use the top-left red triangle to 'Copy Table Script (No Data)'.
// By convention, JSL uses 'dt' in the variable name that holds a handle to a table.
dtFrustration = New Table( "frustration",
New Column( "temp" ), // continuous numeric by default
New Column( "press" ),
New Column( "time" )
);
// because the table might be linked to other reports, there
// is a lot of hidden messaging when the table changes. A lot.
// The messaging can be shut off and later enabled for a nice speedup.
// (to see it take longer, rerun just the loop below.)
// dtFrustration << BeginDataUpdate; // pair with EndDataUpdate, below
For( temp = 1, temp <= 10, temp++,
For( press = 5, press <= 20, press += 5,
For( time = 1, time <= 1000, time += 20,
dtFrustration << addrows( 1 );
dtFrustration:time = time;
dtFrustration:temp = temp;
dtFrustration:press = press;
)
)
);
// dtFrustration << EndDataUpdate;
Re: SAS to JSL - Do Loops...I find it easier to learn by example, so look at as much code as you can find in this forum. Once you get going the scripting index will truly be your friend.
The JSL for loops and if statement, although simple in concept, were a bit baffling to me initially. To shorten your learning curve about if, remember that it is a function, and the comma represents then, else if and else. Open a script window (ctrl-T), right-click in the window and select Show Embedded Log. Paste the below code in and click ctrl-R to run it. Play around with different values for a, b and c to see what happens.
a = 1;
b = 2;
c = 1;
if (a == b,
// then
print("a is equal to b");
,
// else if
a == c,
// then
print("a is equal to c");
,
// else
print("No match found for a");
);
Re: SAS to JSL - Do Loops...THank you... this is helpful.
Re: SAS to JSL - Do Loops...I hear what you are saying... thank you... but, it's kind of like someone telling you to read the Bible to understand Christianity....I spent about 2 hours in the scripting guide looking for how to do this seemingly easy concept... additionally, I have had lots of success writing other scripts... but honestly, the scripting guide makes me yearn for an additional 20k in the budget for a SAS license.
I am not a hardcore coder... I am an engineer just trying to get stuff done fast.
Re: SAS to JSL - Do Loops...Thanks for the help pmroz
Re: SAS to JSL - Do Loops...C++ Programmer's Guide to JSL might be of some help too. It tries to show how the JSL for statement is really a function, and knowing that will make it a lot easier to get the syntax right.
Re: SAS to JSL - Do Loops...All of this is covered in the Scripting Guide, which I very, very strongly recommend you read. It is available in the JMP Documentation Library, available under the Help pull down menu in JMP.
Re: SAS to JSL - Do Loops...You've come to the right place for assistance learning JSL. The scripting index is your friend, as is the on-line documentation.
Here's a code snippet that does what you want:
dt = data table("frustration");
for (temp = 1, temp <= 10, temp++,
for (press = 5, press <= 20, press+=5,
for (time = 1, time <= 1000, time+=20,
show(temp, press, time); // output
);
);
);