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
MattP
Level I

Recode multiple values in multiple columns

Hello JMP Experts,

 

I am tying to recode 103 columns of data in a data table. There are quite a few recodes that need to happen in each column. I was trying to follow this post:

https://community.jmp.com/t5/Discussions/Recode-multiple-columns-with-JSL-script/m-p/7865#M7859

but use recode instead of "if".

 

I think my problem is with the "cols" I used. I'm unsure how to reference the column I am targeting and move from one column to the next with each loop inside of the "for". 

 

Thank you for your help!

 

 

cols = dtconcat << get column names;
For Each Row( For(i=1, i<=N Items(cols), i++,
	cols(i) = Match( cols(i),
		"NQ", "0",
		"Nq", "0",
		"NA", ".",
		"N/A", ".",
		">30", "30",
		">20", "20",
		"<5", "0",
		"<2.00", "0",
		"<2.0", "0",
		"<2", "0",
		"<1", "0",
		"<0.5", "0",
		"<0.01", "0",
		"#N/A", ".",
		"-", ".",
		cols(i))
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Recode multiple values in multiple columns

You have 2 issues.  

  1. The proper syntax for using a subscript is to inclose it in "[ ]" not "( )".
  2. You need to tell JMP that Cols[i] is to be used as a column reference

See the corrected script below

cols = dtconcat << get column names;
For Each Row(
	For( i = 1, i <= N Items( cols ), i++,
		As Column( cols[i] ) =
		Match( As Column( cols[i] ),
			"NQ", "0",
			"Nq", "0",
			"NA", ".",
			"N/A", ".",
			">30", "30",
			">20", "20",
			"<5", "0",
			"<2.00", "0",
			"<2.0", "0",
			"<2", "0",
			"<1", "0",
			"<0.5", "0",
			"<0.01", "0",
			"#N/A", ".",
			"-", "."
		)
	)
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Recode multiple values in multiple columns

You have 2 issues.  

  1. The proper syntax for using a subscript is to inclose it in "[ ]" not "( )".
  2. You need to tell JMP that Cols[i] is to be used as a column reference

See the corrected script below

cols = dtconcat << get column names;
For Each Row(
	For( i = 1, i <= N Items( cols ), i++,
		As Column( cols[i] ) =
		Match( As Column( cols[i] ),
			"NQ", "0",
			"Nq", "0",
			"NA", ".",
			"N/A", ".",
			">30", "30",
			">20", "20",
			"<5", "0",
			"<2.00", "0",
			"<2.0", "0",
			"<2", "0",
			"<1", "0",
			"<0.5", "0",
			"<0.01", "0",
			"#N/A", ".",
			"-", "."
		)
	)
);
Jim
MattP
Level I

Re: Recode multiple values in multiple columns

Thank you very much!

Recommended Articles