cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP Add-In to set precision of data shown in a data table

This add-in makes it easy to set the visible precision of data shown in a data table.  The data is not altered in any way, the only thing that's changed is the precision that is visible.  For example, if a column had data with 9 digits of precision, you can make 3 digits of precision visible, but the original 9 digits are still there.  In this context, "digits of precision" refers to the number of digits to the right of the decimal point.

 

You don't really need an add-in to do this.  The format of a column can be changed using column properties.  This can done on many columns at one time using "Standardized Attributes".  The video shows how to do this using all three methods: 1) using the add-in, 2) setting a column property, and 3) using Standardized Attributes.

 

Considering that this can be done easily using standard JMP menu commands, perhaps the most useful thing about this post is to consider it as an illustration of JMP scripting and how to script a column dialog (selecting specific columns to do something with).  With that in mind, I've included the JSL code within this post.

 

If you want to load the add-in, just download the add-in file to your computer and use JMP to open the file.  Then JMP will ask if you want to install the add-in.

 

Here is what the user interface looks like:

Set Precision GUI.png

 

Here is a short demonstration video of all three methods mentioned above:

 

 

Here is the JSL code used by the add-in:

/*
	
Routine to set column precision on columns selected by a column dialog box.

Hyde Miller
JMP Systems Engineer
10/28/20

*/

Names Default to Here( 1 );

disclaimer = Expr(
	New Window( "License Agreement",
		Modal,
		Outline Box( "License Agreement for Corrective Code or Additional Functionality",
			H List Box(
				Spacer Box( Size( 50, 50 ) ),
				V Scroll Box(
					Size( 500 ),
					Flexible( 1 ),
					Text Box(
						"SAS INSTITUTE INC. IS PROVIDING YOU WITH THE COMPUTER SOFTWARE CODE INCLUDED WITH THIS AGREEMENT (\!"CODE\!") ON AN \!"AS IS\!" BASIS, AND AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS HEREOF. BY USING THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR OWN RISK. SAS INSTITUTE INC. MAKES NO REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED,
 INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE, WITH RESPECT TO THE CODE.

 The Code is intended to be used solely as part of a product (\!"Software\!") you currently have licensed from SAS or one of its subsidiaries or authorized agents (\!"SAS\!"). The Code is designed to either correct an error in the Software or to add functionality to the Software, but has not necessarily been tested. Accordingly, SAS makes no representation or warranty that the Code will operate error-free. SAS is under no obligation to maintain
 or support the Code.

 Neither SAS nor its licensors shall be liable to you or any third party for any general, special, direct, indirect, consequential, incidental or other damages whatsoever arising out of or related to your use or inability to use the Code, even if SAS has been advised of the possibility of such damages. Except as otherwise provided above, the Code is governed by the same agreement that governs the Software. If you do not have an existing agreement with SAS governing the Software, you may not use the Code. (SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.)
",
						<<Set Wrap( 500 )
					)
				)
			)
		)
	)
);
build_col_dialog = Expr(
	col_dialog << Append(
		V List Box(
			Panel Box( "Column Selector",
				H List Box(
					Panel Box( "Select Columns", chooseme = Col List Box( All, width( 200 ), nlines( 10 ) ) ),
					Panel Box( "Cast Selected Columns into Roles",
						H List Box(
							Lineup Box( N Col( 2 ), Spacing( 3 ),
								Button Box( "Selected Columns",
									chosen_y << Append( chooseme << GetSelected );
									chosen_y_cols = chosen_y << GetItems;
								),
								chosen_y = Col List Box( width( 200 ), nlines( 5 ), MinItems( 1 ) ),
							),
							Button Box( "Remove",
								chosen_y << Remove Selected;
								chosen_y_cols = chosen_y << GetItems;
							)
						)
					)
				)
			)
		)
	);
);
run_program = Expr(
	nw << Close Window;
	this_precision = digits_neb << Get;
	num_selected_cols = N Items( chosen_y_cols );
	For(col_loop = 1, col_loop <= num_selected_cols, col_loop++,
		this_col = chosen_y_cols[col_loop];
		this_col_type = Column(dt, this_col) << Get Data Type;
		If( this_col_type == "Numeric",
			Column(dt, this_col) << Format("Fixed Dec", 12, this_precision);
		);
	);
);
quit_program = Expr(
	nw << Close Window;
	Throw();
);
dt = Current Data Table();
nw = New Window( "Set Precision",
	V List Box( 
		col_dialog = V List Box()
	),
	Text Box(""),
	H List Box(
		Text Box("  Number of Digits of Precision: "),
		digits_neb = Number Edit Box( 3 );
		
	),
	Text Box(""),
	H List Box(
		Button Box( "Set Precision on Selected Columns", run_program ),
		Button Box( "Quit", quit_program )
	),
	Text Box(""),
	Button Box("Disclaimer", disclaimer),
);
build_col_dialog;

 

 

 

 

Recommended Articles