Choose Language Hide Translation Bar
Highlighted
acfbt
Level I

Help using for loop and conditional to fill in missing values

Hi all,

 

I am working with a excel data set where multiple rows (batches) are merged for a single workorder and a single yield. Once in JMP, the merge cells split and every row but the yield and scrap column are populated with the correct values for each work order.

I need to populate the missing values with the yield value for that work order. I have attached a example data table.

 

I can do this by creating a new column and using a conditional statement with lag but I would like to do this without a new column.

// example of populating missing values with new column
dt << new column("test", numeric, continuous, set each value(if( :WorkOrder == lag(:WorkOrder,1)& is missing(:yield),:yield= lag(:yield,1),:yield)));

My first thought was to use a for loop but I'm having trouble. The script below runs but does not populate any data in place of the missing values. Could someone please suggest a better way to do this?

dt = current data table();

n=nrows(dt);
for(i=0,i<=n, i++,
	if( :workorder == lag(:workorder,1)& is missing(:yield),:yield= lag(:yield,1),:yield)
);

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Help using for loop and conditional to fill in missing values

In a script, using a For() loop, you need to specify the row by using a subscript.  See below

Names Default To Here( 1 );
dt = Current Data Table();


For( i = 2, i <= N Rows( dt ), i++,
	If( :workorder[i] == :workorder[i - 1] & Is Missing( :yield[i] ),
		:yield[i] = :yield[i - 1]
	)
);
Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Help using for loop and conditional to fill in missing values

In a script, using a For() loop, you need to specify the row by using a subscript.  See below

Names Default To Here( 1 );
dt = Current Data Table();


For( i = 2, i <= N Rows( dt ), i++,
	If( :workorder[i] == :workorder[i - 1] & Is Missing( :yield[i] ),
		:yield[i] = :yield[i - 1]
	)
);
Jim

View solution in original post

Highlighted
acfbt
Level I

Re: Help using for loop and conditional to fill in missing values

Thank you very much, that works perfectly.

Article Labels

    There are no labels assigned to this post.