cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Kelly
Level III

How do I get the returned variable of my function to be assigned to my new variable?

I have created and tested a function called JoinTables. This function will return a data table. I would like the returned datatable to be assigned to the dtSlopeTable variable. 

 

	dtSlopeTable = JoinTables(dataTableList, columnGroup);
	

When I run this, the output table is created with the desired content but it is not associated with the variable name "dtSlopeTable".

 

When I check the value of dtSlopeTable, it says Data Table( "UnknownTable" ).
I have tried wait(0) and wait(10) but niether work.

However, I am able to get it working if I use wait(0) and the line before has:

dtTest = New table();

 

 

This is a weird work around and I would perfer to use a clean solution. Do you have an idea of why I can't assign the table to the variable name?
If you need to view the function definition, I would be happy to attach.

Thanks for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I get the returned variable of my function to be assigned to my new variable?

What is returned to the calling statement is the last item processed in the function, so all you should have to do is to place the handle you are calling the new data table as the last item, and it will return it to the calling variable.  See the simple example below

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt2 = New Table( "lookup",
	New Column( "Sex", character, values( {"F", "M"} ) ),
	New Column( "Avg Height", values( {68, 70} ) )
);

joinTables = Function( {x1, x2, m1},{},
	dtFinal = x1 << join( With( x2 ), Merge same name columns(1), Match Columns( Column( m1 ) == Column( m1 ) ) );
	dtFinal;
);

dtSlopeTable=joinTables(dt,dt2,"Sex");

show(dtSlopeTable);
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: How do I get the returned variable of my function to be assigned to my new variable?

What is returned to the calling statement is the last item processed in the function, so all you should have to do is to place the handle you are calling the new data table as the last item, and it will return it to the calling variable.  See the simple example below

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
dt2 = New Table( "lookup",
	New Column( "Sex", character, values( {"F", "M"} ) ),
	New Column( "Avg Height", values( {68, 70} ) )
);

joinTables = Function( {x1, x2, m1},{},
	dtFinal = x1 << join( With( x2 ), Merge same name columns(1), Match Columns( Column( m1 ) == Column( m1 ) ) );
	dtFinal;
);

dtSlopeTable=joinTables(dt,dt2,"Sex");

show(dtSlopeTable);
Jim