cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Due to global connectivity issues impacting AWS Services, users may experience unexpected errors while attempting to authorize JMP. Please try again later or contact support@jmp.com to be notified once all issues are resolved.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
axcelenator1
Level III

Generating Columns with a for loop

Hello, I try to generate several columns with the next JSL script line but when running the script the data table is blank: 

 

	For(i=0,i<3,i++,New Column( "A", Numeric, Continuous, Format( "Best", 10 ), Set Values( [1, 2, 3, .] )))

How can it be fixed?

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Generating Columns with a for loop

Again, make the table first and then add the columns.  Here is some code that does what you want (I think):

 

Names default to here( 1 );

//Make the data table
dt = New Table( "Tokens",
	Add Rows( 3 ),
	New Column( "Visual_ID", Character, Nominal, Set Values( {"88", "89", "94"} ) ),
	New Column( "FF", Character, Nominal, Set Values( {"Y83", "YA8", "654"} ) ),
	New Column( "Bipping",
		Character,
		Nominal,
		Set Selected,
		Set Values(
			{"19|19|19|16|14|16|19|18|18|21|17|20|20|19|19|20|17|18|18",
			"19|19|19|16|14|16|19|18|18|21|17|20|20|19|19|20|18|18|18",
			"19|18|18|18|17|18|16|18|18|19|21|19|19|18|18|17|16|16|17"}
		)
	)
);

//Then add columns to it.
For( ii = 1, ii<19, ii++, 
	dt << New Column  ("My_Column_" || Char(ii), 
		Character, 
		Nominal, 
		Formula(
				Word( ii, As Column( Column( "Bipping"  ) ), "|" )
			
				)
			
	)
);

View solution in original post

3 REPLIES 3
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Generating Columns with a for loop

The syntax looks correct so I suspect the issue is with the context that you are using it.  To make this work, first create a table and then your add new columns.  To ensure columns are created in the correct table, make a reference to that table and 'send' the New Column message to it, as shown below:

Names default to here( 1 );

//Open a blank table and save a reference to it
dt = New Table( "New Table", Add Rows( 0 ) );

//Add columns to the table
For( i=0, i<3, i++,
	dt << New Column( "A", Numeric, Continuous, Format( "Best", 10 ), Set Values( [1, 2, 3, .] ))
);
axcelenator1
Level III

Re: Generating Columns with a for loop

Can you look here please: https://community.jmp.com/t5/Discussions/Loop-is-not-working/m-p/77361#M36165

In the above link I try to make something similar but it not works

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Generating Columns with a for loop

Again, make the table first and then add the columns.  Here is some code that does what you want (I think):

 

Names default to here( 1 );

//Make the data table
dt = New Table( "Tokens",
	Add Rows( 3 ),
	New Column( "Visual_ID", Character, Nominal, Set Values( {"88", "89", "94"} ) ),
	New Column( "FF", Character, Nominal, Set Values( {"Y83", "YA8", "654"} ) ),
	New Column( "Bipping",
		Character,
		Nominal,
		Set Selected,
		Set Values(
			{"19|19|19|16|14|16|19|18|18|21|17|20|20|19|19|20|17|18|18",
			"19|19|19|16|14|16|19|18|18|21|17|20|20|19|19|20|18|18|18",
			"19|18|18|18|17|18|16|18|18|19|21|19|19|18|18|17|16|16|17"}
		)
	)
);

//Then add columns to it.
For( ii = 1, ii<19, ii++, 
	dt << New Column  ("My_Column_" || Char(ii), 
		Character, 
		Nominal, 
		Formula(
				Word( ii, As Column( Column( "Bipping"  ) ), "|" )
			
				)
			
	)
);

Recommended Articles