cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
scott1588
Level IV

Simple Looping Question

I have what I think is a very simple looping question. I've looked in the scripting index and scripting guide and I just can't seem to figure it out.

 

All I need to do is to create a table with a list of years beginning with defined earliest year and going to a defined latest year. So say 1960, 1961, 1962, etc. with one year in each row. The script I am using returns a blank column. Here it is...

 

Names Default to Here(1);

minYear = 1947;
maxYear = 2024;

dt = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear),
	New Column("Year", Ordinal) 
);

For (i=minYear, i<maxYear, i++, for each row(i));

Can someone tell me what I'm missing here?

 

Thanks much as always.

2 ACCEPTED SOLUTIONS

Accepted Solutions
hogi
Level XII

Re: Simple Looping Question

For each row is a for loop like for() or for each(). So, you can use it directly like in the example below, no need to combine it with a for loop.
There are also other possibilities to set the values.

 

Names Default to Here(1);

minYear = 1947;
maxYear = 2024;

dt1 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal) 
);
for each row(:Year = row()-1+ minYear);

dt2 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal, set each value(row()-1+ minYear)) 
);

myYears = 1947::2024;
dt3 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal, set values(myYears)) 
);

 

View solution in original post

txnelson
Super User

Re: Simple Looping Question

Here is one way to do it

Names Default To Here( 1 );

minYear = 1947;
maxYear = 2024;

dt = New Table( "Years by Quarter",
	Add Rows( maxYear - minYear ),
	New Column( "Year",
		Ordinal,
		set each value( minYear + Row() )
	)
);
Jim

View solution in original post

3 REPLIES 3
hogi
Level XII

Re: Simple Looping Question

For each row is a for loop like for() or for each(). So, you can use it directly like in the example below, no need to combine it with a for loop.
There are also other possibilities to set the values.

 

Names Default to Here(1);

minYear = 1947;
maxYear = 2024;

dt1 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal) 
);
for each row(:Year = row()-1+ minYear);

dt2 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal, set each value(row()-1+ minYear)) 
);

myYears = 1947::2024;
dt3 = New Table ("Years by Quarter",
	Add Rows (maxYear - minYear +1),
	New Column("Year", Ordinal, set values(myYears)) 
);

 

txnelson
Super User

Re: Simple Looping Question

Here is one way to do it

Names Default To Here( 1 );

minYear = 1947;
maxYear = 2024;

dt = New Table( "Years by Quarter",
	Add Rows( maxYear - minYear ),
	New Column( "Year",
		Ordinal,
		set each value( minYear + Row() )
	)
);
Jim
scott1588
Level IV

Re: Simple Looping Question

Thanks to both of you! Gradually I am starting the get the hang of JSL.