<?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 Re: jsl script to recode multiple columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347546#M59832</link>
    <description>&lt;P&gt;Do you have to recode values or could you possibly use column property Value Labels (this way you won't loose the original data), example:&amp;nbsp;&lt;LI-MESSAGE title="Recode multiple columns with JSL script" uid="7865" url="https://community.jmp.com/t5/Discussions/Recode-multiple-columns-with-JSL-script/m-p/7865#U7865" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;And if you have to recode them in place, there are multiple ways to do it (I would use Associative Array):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt3 = current data Table ();
n3 = dt3 &amp;lt;&amp;lt; Get Column Names(string);
show(n3);
//create associative array to use matching keys to values
matchAa = Associative Array(
	{"1","2","3","4","5"}, 
	{"too low","too low","right","too high","too high"}
);
show(matchAa);

//loop over column names
For(i = 1, i &amp;lt;= N Items(n3), i++,
	//refer to column and use set each value to update values
	Column(dt3, n3[i]) &amp;lt;&amp;lt; Set Each Value(
		matchAa[AsColumn(n3[i])[Row()]]
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And for your solution I think there is an issue in how you refer to values in Match function and you have to add [Row()] to get single values for Matching&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match(As Column( lstColNames_n3[i])[Row()],&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Edit2:&lt;/P&gt;
&lt;P&gt;Added full example script as attachment&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jan 2021 12:58:27 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-01-12T12:58:27Z</dc:date>
    <item>
      <title>jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347505#M59830</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;I am trying to recode multiple columns by using the following script (also in attachment together with an example data table). I tried several changes but it does not work. The values in the columns just disappears instead of being recoded.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate any help.&lt;/P&gt;
&lt;P&gt;Many thanks,&lt;BR /&gt;Marcello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt3 = Current Data Table();
n3 = dt3 &amp;lt;&amp;lt; Get Column Names();
Show( n3 );

lstColNames_n3 = dt3 &amp;lt;&amp;lt; Get Column Names();
Show( lstColNames_n3 );


Show( lstCols_n3 );
lstCols_n3 = {};
For( i = 1, i &amp;lt;= N Items( lstColNames_n3 ), i++,
    colName = lstColNames_n3[i];
    col = Column( dt3, i );
    Insert Into( lstCols_n3, col );
);
Show( lstCols_n3 );

For Each Row(
    For( i = 1, i &amp;lt;= N Items( lstColNames_n3 ), i++,
        As Column( lstColNames_n3[i] ) = Match( As Column( lstColNames_n3[i] ),
            "1", "too low",
            "2", "too low",
            "3", "right",
            "4", "too high",
            "5", "too high"
        )
    )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:02:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347505#M59830</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2023-06-09T22:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347546#M59832</link>
      <description>&lt;P&gt;Do you have to recode values or could you possibly use column property Value Labels (this way you won't loose the original data), example:&amp;nbsp;&lt;LI-MESSAGE title="Recode multiple columns with JSL script" uid="7865" url="https://community.jmp.com/t5/Discussions/Recode-multiple-columns-with-JSL-script/m-p/7865#U7865" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;And if you have to recode them in place, there are multiple ways to do it (I would use Associative Array):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt3 = current data Table ();
n3 = dt3 &amp;lt;&amp;lt; Get Column Names(string);
show(n3);
//create associative array to use matching keys to values
matchAa = Associative Array(
	{"1","2","3","4","5"}, 
	{"too low","too low","right","too high","too high"}
);
show(matchAa);

//loop over column names
For(i = 1, i &amp;lt;= N Items(n3), i++,
	//refer to column and use set each value to update values
	Column(dt3, n3[i]) &amp;lt;&amp;lt; Set Each Value(
		matchAa[AsColumn(n3[i])[Row()]]
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And for your solution I think there is an issue in how you refer to values in Match function and you have to add [Row()] to get single values for Matching&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Match(As Column( lstColNames_n3[i])[Row()],&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Edit2:&lt;/P&gt;
&lt;P&gt;Added full example script as attachment&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 12:58:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347546#M59832</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-01-12T12:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347567#M59835</link>
      <description>I would need to recode values. Thanks.&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Jan 2021 09:52:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347567#M59835</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-01-12T09:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347569#M59837</link>
      <description>I edited my previous reply, it should help with the recoding</description>
      <pubDate>Tue, 12 Jan 2021 09:55:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347569#M59837</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-01-12T09:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347574#M59838</link>
      <description>&lt;P&gt;Thank you very much, your code with the associative array worked perfectly.&lt;/P&gt;&lt;P&gt;I tried also the other option, by adding&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;Match(As Column( lstColNames_n3[i])[Row()],&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but that did not work.&lt;/P&gt;&lt;P&gt;But I solved my problem.&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 10:18:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347574#M59838</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-01-12T10:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347575#M59839</link>
      <description>&lt;P&gt;Here is the solution using the Recode feature written in JSL It is much faster than doing row by row processing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dmdt = current data table();

nc = dmdt &amp;lt;&amp;lt; get column names( Character );

For( i = 1, i &amp;lt;= N Items( nc ), i++,
	col = Column( dt, nc[i] );
	colname = col &amp;lt;&amp;lt; getname();

	Eval(
		Parse(
			Eval Insert(
				"\[
		dmdt &amp;lt;&amp;lt; Recode Column(
			:Name("^colname^"),
			{Map Value( _rcOrig, 
			{	"1", "too low",
				"2", "too low",
				"3", "right",
				"4", "too high",
				"5", "too high"}, 
			Unmatched( _rcNow ) )},
			Update Properties( 1 ),
			Target Column( :Name("^colname^") )
		);
	]\"
			)
		)
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 10:33:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347575#M59839</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-01-12T10:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347759#M59871</link>
      <description>&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 18:01:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/347759#M59871</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-01-12T18:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/349010#M59985</link>
      <description>One work-around solution would be creating a new column with formula based on the column you want to recode.&lt;BR /&gt;Then delete the original column :)&lt;/img&gt;</description>
      <pubDate>Fri, 15 Jan 2021 04:31:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/349010#M59985</guid>
      <dc:creator>ThuongLe</dc:creator>
      <dc:date>2021-01-15T04:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: jsl script to recode multiple columns</title>
      <link>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/349140#M59988</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2021 09:40:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/jsl-script-to-recode-multiple-columns/m-p/349140#M59988</guid>
      <dc:creator>MFVIT</dc:creator>
      <dc:date>2021-01-15T09:40:54Z</dc:date>
    </item>
  </channel>
</rss>

