cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
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
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
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
acfbt
Level I

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

Thank you very much, that works perfectly.