cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
fat_angus
Level III

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. 

  

 

12 REPLIES 12
fat_angus
Level III

Re: SAS to JSL - Do Loops...

This is great Craige_HALES! 

 

I very much appreciate you taking time to explain. 

Jeff_Perkinson
Community Manager Community Manager

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.

2022-01-20_17-37-56.951.png

Temp columnTemp column

I'd do the same for the other columns.

press columnpress column

time columntime column

 

After adding rows to the data table you'll end up with this:

2022-01-20_17-42-26.079.png

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

2022-01-20_17-43-42.929.png

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!

-Jeff
fat_angus
Level III

Re: 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