<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic batching recoding of many columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368066#M61792</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to recode many columns which contain a specific string in their column name using the recode function. I think I'm pretty close but the script is getting stuck with the column evaluations. So I'm missing something crucial somewhere. Any guidance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
Clear log();

New Table( "Subject_Demographics",
	Add Rows( 48 ),
	New Column( "Unique Subject Identifier",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"8396882-P0101", "8396882-P0101", "8396882-P0102", "8396882-P0102",
			"8396882-P0103", "8396882-P0103", "8396882-P0104", "8396882-P0104",
			"8396882-P0201", "8396882-P0201", "8396882-P0202", "8396882-P0202",
			"8396882-P0203", "8396882-P0203", "8396882-P0204", "8396882-P0204",
			"8396882-P0301", "8396882-P0301", "8396882-P0302", "8396882-P0302",
			"8396882-P0303", "8396882-P0303", "8396882-P0304", "8396882-P0304",
			"8396882-P0401", "8396882-P0401", "8396882-P0402", "8396882-P0402",
			"8396882-P0403", "8396882-P0403", "8396882-P0404", "8396882-P0404",
			"8396882-P0501", "8396882-P0501", "8396882-P0502", "8396882-P0502",
			"8396882-P0503", "8396882-P0503", "8396882-P0504", "8396882-P0504",
			"8396882-P0601", "8396882-P0601", "8396882-P0602", "8396882-P0602",
			"8396882-P0603", "8396882-P0603", "8396882-P0604", "8396882-P0604"}
		)
	),
	New Column( "Alertness - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"", "", "", "", "", "", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "", "", "",
			"", "", ""}
		)
	),
	New Column( "Xyx Reflex - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "", "", "", "", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Abnormal Finding", "Abnormal Finding", "Normal", "Normal",
			"Normal", "Normal", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal"}
		)
	),
	New Column( "Ataxia - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "", "", "Abnormal Finding", "Abnormal Finding", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding"}
		)
	)
);


subject_incidence = Data Table( "Subject_Demographics" );
a = "Recoded";
col = subject_incidence &amp;lt;&amp;lt; get column names( string );
show(col);
nc = N Items( col );
For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], a ), 	
		subject_incidence &amp;lt;&amp;lt; Begin Data Update;
		subject_incidence &amp;lt;&amp;lt; Recode Column(
			column(subject_incidence, col[i]),
			{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
			Target Column( column(subject_incidence, col[i] ))
		);
		subject_incidence &amp;lt;&amp;lt; End Data Update
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Jun 2023 22:08:31 GMT</pubDate>
    <dc:creator>Sburel</dc:creator>
    <dc:date>2023-06-09T22:08:31Z</dc:date>
    <item>
      <title>batching recoding of many columns</title>
      <link>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368066#M61792</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to recode many columns which contain a specific string in their column name using the recode function. I think I'm pretty close but the script is getting stuck with the column evaluations. So I'm missing something crucial somewhere. Any guidance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sebastien&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
Clear log();

New Table( "Subject_Demographics",
	Add Rows( 48 ),
	New Column( "Unique Subject Identifier",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"8396882-P0101", "8396882-P0101", "8396882-P0102", "8396882-P0102",
			"8396882-P0103", "8396882-P0103", "8396882-P0104", "8396882-P0104",
			"8396882-P0201", "8396882-P0201", "8396882-P0202", "8396882-P0202",
			"8396882-P0203", "8396882-P0203", "8396882-P0204", "8396882-P0204",
			"8396882-P0301", "8396882-P0301", "8396882-P0302", "8396882-P0302",
			"8396882-P0303", "8396882-P0303", "8396882-P0304", "8396882-P0304",
			"8396882-P0401", "8396882-P0401", "8396882-P0402", "8396882-P0402",
			"8396882-P0403", "8396882-P0403", "8396882-P0404", "8396882-P0404",
			"8396882-P0501", "8396882-P0501", "8396882-P0502", "8396882-P0502",
			"8396882-P0503", "8396882-P0503", "8396882-P0504", "8396882-P0504",
			"8396882-P0601", "8396882-P0601", "8396882-P0602", "8396882-P0602",
			"8396882-P0603", "8396882-P0603", "8396882-P0604", "8396882-P0604"}
		)
	),
	New Column( "Alertness - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"", "", "", "", "", "", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "", "", "",
			"", "", ""}
		)
	),
	New Column( "Xyx Reflex - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "", "", "", "", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Abnormal Finding", "Abnormal Finding", "Normal", "Normal",
			"Normal", "Normal", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal"}
		)
	),
	New Column( "Ataxia - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "", "", "Abnormal Finding", "Abnormal Finding", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding"}
		)
	)
);


subject_incidence = Data Table( "Subject_Demographics" );
a = "Recoded";
col = subject_incidence &amp;lt;&amp;lt; get column names( string );
show(col);
nc = N Items( col );
For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], a ), 	
		subject_incidence &amp;lt;&amp;lt; Begin Data Update;
		subject_incidence &amp;lt;&amp;lt; Recode Column(
			column(subject_incidence, col[i]),
			{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
			Target Column( column(subject_incidence, col[i] ))
		);
		subject_incidence &amp;lt;&amp;lt; End Data Update
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:08:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368066#M61792</guid>
      <dc:creator>Sburel</dc:creator>
      <dc:date>2023-06-09T22:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: batching recoding of many columns</title>
      <link>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368124#M61795</link>
      <description>&lt;P&gt;Inside the recode column function, JMP doesn't know about the variable col anymore, so you need to evaluate that part of the script&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the recode column evaluates.&amp;nbsp; To do that, you can use the Eval, Eval Expr, and Expr functions, like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dtSD = New Table( "Subject_Demographics",
	Add Rows( 48 ),
	New Column( "Unique Subject Identifier",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"8396882-P0101", "8396882-P0101", "8396882-P0102", "8396882-P0102",
			"8396882-P0103", "8396882-P0103", "8396882-P0104", "8396882-P0104",
			"8396882-P0201", "8396882-P0201", "8396882-P0202", "8396882-P0202",
			"8396882-P0203", "8396882-P0203", "8396882-P0204", "8396882-P0204",
			"8396882-P0301", "8396882-P0301", "8396882-P0302", "8396882-P0302",
			"8396882-P0303", "8396882-P0303", "8396882-P0304", "8396882-P0304",
			"8396882-P0401", "8396882-P0401", "8396882-P0402", "8396882-P0402",
			"8396882-P0403", "8396882-P0403", "8396882-P0404", "8396882-P0404",
			"8396882-P0501", "8396882-P0501", "8396882-P0502", "8396882-P0502",
			"8396882-P0503", "8396882-P0503", "8396882-P0504", "8396882-P0504",
			"8396882-P0601", "8396882-P0601", "8396882-P0602", "8396882-P0602",
			"8396882-P0603", "8396882-P0603", "8396882-P0604", "8396882-P0604"}
		)
	),
	New Column( "Alertness - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"", "", "", "", "", "", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding", "", "", "",
			"", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "", "", "",
			"", "", ""}
		)
	),
	New Column( "Xyx Reflex - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "", "", "", "", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Abnormal Finding", "Abnormal Finding", "Normal", "Normal",
			"Normal", "Normal", "", "", "", "", "Abnormal Finding",
			"Abnormal Finding", "Normal", "Normal", "Normal", "Normal", "Normal",
			"Normal", "Normal", "Normal", "Normal", "Normal"}
		)
	),
	New Column( "Ataxia - Recoded",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "Abnormal Finding", "", "", "Abnormal Finding",
			"Abnormal Finding", "", "", "", "", "", "", "", "", "", "", "", "",
			"Abnormal Finding", "Abnormal Finding", "Abnormal Finding",
			"Abnormal Finding", "", "", "Abnormal Finding", "Abnormal Finding", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding", "", "", "", "", "",
			"", "", "", "Abnormal Finding", "Abnormal Finding"}
		)
	)
);


a = "Recoded";
col = dtSD &amp;lt;&amp;lt; get column names( );

dtSD &amp;lt;&amp;lt; Begin Data Update;
For( i = 1, i &amp;lt;= N Items( col ), i++,
	If( Contains( col[i], a ), 	
		
		//Need to evaluate the name of the column before 
		e = Eval Expr( 
			Expr( dtSD ) &amp;lt;&amp;lt; Recode Column(
				As Column( Expr( col[i] ) ),
				{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
				Target Column( As Column( Expr( col[i] ) ) )
			);
		);
		show(e); write("\!n");
		eval(e);
	)
);

dtSD &amp;lt;&amp;lt; End Data Update
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I saved the expression as e so it could be written to the log before being evaluated.&amp;nbsp; You could have put Eval( Eval Expr( on the same line.&lt;BR /&gt;&lt;BR /&gt;There are many ways to construct this code, here are a few examples:&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 02:06:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368124#M61795</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2021-03-16T02:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: batching recoding of many columns</title>
      <link>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368140#M61798</link>
      <description>&lt;P&gt;I believe the code can be a little simpler than&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6657"&gt;@ih&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code with just a change to using an As Column() function rather than just a Column() function allows the code to run correctly&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;subject_incidence = Data Table( "Subject_Demographics" );
a = "Recoded";
col = subject_incidence &amp;lt;&amp;lt; get column names( string );
show(col);
nc = N Items( col );
For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], a ), 	
		subject_incidence &amp;lt;&amp;lt; Begin Data Update;
		subject_incidence &amp;lt;&amp;lt; Recode Column(
			as column(subject_incidence, col[i]),
			{Map Value( _rcOrig, {"", "Not Reported"}, Unmatched( _rcNow ) )},
			Target Column( column(subject_incidence, col[i] ))
		);
		subject_incidence &amp;lt;&amp;lt; End Data Update
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is also a different approach to solve your issue by using Get Rows Where() to find the rows that have no value, and changing those rows value to Not Reported&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;subject_incidence = Data Table( "Subject_Demographics" );
a = "Recoded";
col = subject_incidence &amp;lt;&amp;lt; get column names( string );
Show( col );
nc = N Items( col );
For( i = 1, i &amp;lt;= nc, i++,
	If( Contains( col[i], a ),
		Try(
			Column( subject_incidence, col[i] )[subject_incidence &amp;lt;&amp;lt;
			get rows where( as Column( subject_incidence, col[i] ) == "" )] = "Not Reported"
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Mar 2021 04:21:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/batching-recoding-of-many-columns/m-p/368140#M61798</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-16T04:21:20Z</dc:date>
    </item>
  </channel>
</rss>

