<?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: create a weight Column in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49782#M28324</link>
    <description>&lt;P&gt;Great Jim, Thanks very much.&lt;/P&gt;&lt;P&gt;i will adapt your code to my job&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jan 2018 16:26:22 GMT</pubDate>
    <dc:creator>gianpaolo</dc:creator>
    <dc:date>2018-01-17T16:26:22Z</dc:date>
    <item>
      <title>create a weight Column</title>
      <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49711#M28282</link>
      <description>&lt;P&gt;Good morning.&lt;/P&gt;&lt;P&gt;using JSL code, starting from a column with GOOD / BAD rows, i would like to create a new WEIGHT COLUMN, where&amp;nbsp;BAD =1 and GOOD = Ratio BAD/GOOD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;There is&amp;nbsp;JSL to do it quickly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;&lt;P&gt;Gianpaolo&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 09:25:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49711#M28282</guid>
      <dc:creator>gianpaolo</dc:creator>
      <dc:date>2018-01-16T09:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: create a weight Column</title>
      <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49714#M28283</link>
      <description>Can you kindly provide sample data of your column to understand what GOOD / BAD looks like ?</description>
      <pubDate>Tue, 16 Jan 2018 13:29:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49714#M28283</guid>
      <dc:creator>uday_guntupalli</dc:creator>
      <dc:date>2018-01-16T13:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: create a weight Column</title>
      <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49745#M28306</link>
      <description>Split Weight Split where:&lt;BR /&gt;GOOD 0.4 BAD=1&lt;BR /&gt;BAD 1 GOOD = #BAD/#GOOD&lt;BR /&gt;GOOD 0.4 in this case 4/10 =0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;GOOD 0.4&lt;BR /&gt;BAD 1&lt;BR /&gt;BAD 1&lt;BR /&gt;BAD 1&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jan 2018 09:02:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49745#M28306</guid>
      <dc:creator>gianpaolo</dc:creator>
      <dc:date>2018-01-17T09:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: create a weight Column</title>
      <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49779#M28322</link>
      <description>&lt;P&gt;Here are two similar solutions.&lt;/P&gt;
&lt;P&gt;This one generates the new column in open JSL&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create the sample data table
dt = New Table( "Good Bad Ratio",
	Add Rows( 14 ),
	New Column( "Good_Bad",
		Character,
		"Nominal",
		Set Values(
			{"GOOD", "BAD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD",
			"GOOD", "BAD", "BAD", "BAD"}
		)
	)
);

// Create the new column using a formula for the calculation
dt &amp;lt;&amp;lt; New Column( "Weight",
	formula(
		If( Row() == 1,
			TheGoodCount = Col Number( If( :Good_Bad == "GOOD", 1, . ) );
			TheBadCount = Col Number( If( :Good_Bad == "BAD", 1, . ) );
			Ratio = TheBadCount / TheGoodCount;
		);
		If(
			:Good_Bad == "GOOD", Ratio,
			:Good_Bad == "BAD", 1
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This version uses a column formula to create the values for the column Weight&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

// Create the sample data table
dt = New Table( "Good Bad Ratio",
	Add Rows( 14 ),
	New Column( "Good_Bad",
		Character,
		"Nominal",
		Set Values(
			{"GOOD", "BAD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD",
			"GOOD", "BAD", "BAD", "BAD"}
		)
	)
);

// Calculate the Ratio
TheGoodCount = Col Number( If( dt:Good_Bad == "GOOD", 1, . ) );
TheBadCount = Col Number( If( dt:Good_Bad == "BAD", 1, . ) );
Ratio = TheBadCount / TheGoodCount;

// Add the new column and populate it
dt &amp;lt;&amp;lt; New Column( "Weight" );
For Each Row(
	If(
		dt:Good_Bad == "GOOD", dt:Weight = Ratio,
		dt:Good_Bad == "BAD", dt:Weight = 1
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:09:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49779#M28322</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2018-01-17T16:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: create a weight Column</title>
      <link>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49782#M28324</link>
      <description>&lt;P&gt;Great Jim, Thanks very much.&lt;/P&gt;&lt;P&gt;i will adapt your code to my job&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 16:26:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/create-a-weight-Column/m-p/49782#M28324</guid>
      <dc:creator>gianpaolo</dc:creator>
      <dc:date>2018-01-17T16:26:22Z</dc:date>
    </item>
  </channel>
</rss>

