cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Stas
Level III

updating list inside a function

Hey guys,

I'm trying to add a new value (variable value) to a list inside a function, each time the function has been called.

No matter what I tried, the list is not getting any value. 

Any advice?

 

Adding the example of the code

2 REPLIES 2
jthi
Super User

Re: updating list inside a function

I think it is better idea to return the new column and then add that outside of the function call

Names Default To Here(1);

dt = Open("\\VMSPFSFSLC001\F28_PLI\SQL\FE SQL\Data\Oxide .CSV");

op_list = List();

add_new_operation = Function({dt, col_name, op, PLmin, PLmax}, {Default Local},
	new_col = dt << New Column(col_name,
		Character,
		"Nominal",
		Formula(
			If(/*some conditions for the value*/
			)
 		
		)
	);
	
	return(new_col);
);

sticol = add_new_operation(dt, "STI", 201405, 80, 2000);
Insert Into(op_list, sticol);

Show(op_list);


// This should also work
// Insert into(op_list, add_new_operation(dt, "STI", 201405, 80, 2000));

Full example

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

op_list = {};

add_new_operation = Function({dt, col_name}, {Default Local},
	new_col = dt << New Column(col_name,
		Character,
		"Nominal",
		Formula(
			col_name
		)
	);
	
	return(new_col);
);

Show(op_list); // op_list = {};
Insert into(op_list, add_new_operation(dt, "name"));
Insert into(op_list, add_new_operation(dt, "age"));
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};
 
-Jarmo
jthi
Super User

Re: updating list inside a function

And if you really want to insert into the list created outside of the function, remove {Default Local} from your function (there are also other methods) but I wouldn't recommend this. One reason being that now you have to have op_list always created before the function is called.

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

op_list = {};

add_new_operation = Function({dt, col_name},
	new_col = dt << New Column(col_name,
		Character,
		"Nominal",
		Formula(
			col_name
		)
	);
	
	Insert Into(op_list, new_col);
);

Show(op_list); // op_list = {};
add_new_operation(dt, "name");
add_new_operation(dt, "age");
Show(op_list); // op_list = {Column("name 2"), Column("age 2")};
-Jarmo

Recommended Articles