cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

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

Passing column name as argument to a function - is concatenating with : needed?

Below is a function where I am trying to pass a column name for plotting a distribution, but it is not working. I am wondering what is the correct syntax?

Names Default To Here (1);
getDistChart = Function({ColName}, {dC},

dC = Distribution( Continuous Distribution( Column( :ColName) ) );

return(dC);
);
//gt = getDistChart ("MyCol"); to test the function

I have already got the data table with MyCol as a column name open. I am wondering if I need to concatenate

:

 with the column name

ColName

If so how (as normal concatenation with || || does not seem to be working)?

 

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Passing column name as argument to a function - is concatenating with : needed?

Yes, it works perfectly for me with JMP Pro 16.1.0. I do not have any earlier versions of JMP installed to test. Your version is about 5 years old. JSL is constantly evolving, so it is possible that my syntax does not work for an earlier version.

 

You might contact JMP Technical Support ([email protected]) for help.

 

You might also try using expressions to accomplish what you want. They work for any version of JMP, since version 4. See if this version works:

 

Names Default To Here( 1 );

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

getDistChart = Function( {ColName, _LSL, _USL}, {distChart},
	Eval(
		Substitute(
			Expr(
				distChart = New Window( "" || ColName || " distribution", 
					Distribution(
						Stack( 1 ),
						Continuous Distribution(
							Column( As Column( ColName ) ),
							Horizontal Layout( 1 ),
							Vertical( 0 ),
							Capability Analysis( LSL( _LSL ), USL( _USL ) )
						),
						SendToReport(
							Dispatch(
								{ ccc },
								"Distrib Histogram",
								FrameBox,
								{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
								DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
							)
						)
					)
				);
			),
			Expr( ccc ), colName
		)
	);
	Return( distChart );
);

getDistChart( "weight", 55, 185 );

View solution in original post

6 REPLIES 6

Re: Passing column name as argument to a function - is concatenating with : needed?

Names Default To Here( 1 );

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

getDistChart = Function( {ColName}, {dC}, 
	dC = Distribution( Continuous Distribution( Column( As Column( colName ) ) ) );
	Return( dC );
);

gt = getDistChart ("weight");
Neo
Neo
Level VII

Re: Passing column name as argument to a function - is concatenating with : needed?

@Mark_Bailey Thanks it works. However, I am getting stuck advancing to the next step. I would like to pass the column name to several places in my script. Using Big Class as an example below. I am able to pass the ColName to New Window but not to Dispatch 

Names Default To Here (1);

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

getDistChart = Function({ColName, _LSL, _USL}, {distChart},

New Window(""||ColName||" distribution",

Distribution(
	Stack( 1 ),
	Continuous Distribution(
		Column(As Column (ColName) ),
		Horizontal Layout( 1 ),
		Vertical( 0 ),
		Capability Analysis( LSL(_LSL ), USL(_USL) )
	),
	SendToReport(
		Dispatch(
			{"weight"},
			"Distrib Histogram",
			FrameBox,
			{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
			DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
		)
	)
);
);

return(distChart);
);

getDistChart ("weight", 55, 185); 

For example this 

Dispatch(	{ColName},...

or this from here

Dispatch(	{Expr(ColName)},...

does not work. What is the correct syntax to pass a string as argument for Dispatch? 

When it's too good to be true, it's neither

Re: Passing column name as argument to a function - is concatenating with : needed?

Names Default To Here( 1 );

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

getDistChart = Function( {ColName, _LSL, _USL},
	{distChart}, 

	New Window( "" || ColName || " distribution", 

		Distribution(
			Stack( 1 ),
			Continuous Distribution(
				Column( As Column( ColName ) ),
				Horizontal Layout( 1 ),
				Vertical( 0 ),
				Capability Analysis( LSL( _LSL ), USL( _USL ) )
			),
			SendToReport(
				Dispatch(
					{colName},
					"Distrib Histogram",
					FrameBox,
					{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
					DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
				)
			)
		)
	);

	Return( distChart );
);

getDistChart( "weight", 55, 185 );
Neo
Neo
Level VII

Re: Passing column name as argument to a function - is concatenating with : needed?

@Mark_Bailey  Thanks. Running your script gives me the following in the log

Cannot find item "ColName" in outline context {ColName}

Does it work for you?

(I am on JMP 13)

When it's too good to be true, it's neither

Re: Passing column name as argument to a function - is concatenating with : needed?

Yes, it works perfectly for me with JMP Pro 16.1.0. I do not have any earlier versions of JMP installed to test. Your version is about 5 years old. JSL is constantly evolving, so it is possible that my syntax does not work for an earlier version.

 

You might contact JMP Technical Support ([email protected]) for help.

 

You might also try using expressions to accomplish what you want. They work for any version of JMP, since version 4. See if this version works:

 

Names Default To Here( 1 );

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

getDistChart = Function( {ColName, _LSL, _USL}, {distChart},
	Eval(
		Substitute(
			Expr(
				distChart = New Window( "" || ColName || " distribution", 
					Distribution(
						Stack( 1 ),
						Continuous Distribution(
							Column( As Column( ColName ) ),
							Horizontal Layout( 1 ),
							Vertical( 0 ),
							Capability Analysis( LSL( _LSL ), USL( _USL ) )
						),
						SendToReport(
							Dispatch(
								{ ccc },
								"Distrib Histogram",
								FrameBox,
								{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
								DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
							)
						)
					)
				);
			),
			Expr( ccc ), colName
		)
	);
	Return( distChart );
);

getDistChart( "weight", 55, 185 );
Neo
Neo
Level VII

Re: Passing column name as argument to a function - is concatenating with : needed?

Thanks @Mark_Bailey  This works.

 

When it's too good to be true, it's neither

Recommended Articles