cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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.

Recommended Articles