cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

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