<?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: How do you assign a variable from a list to a row in a data table? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/472436#M71712</link>
    <description>&lt;P&gt;My mind initially went to a loop to complete what I wanted to do, but thank you for this alternative solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This categorized my data exactly like I wanted.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 18:28:20 GMT</pubDate>
    <dc:creator>gable64</dc:creator>
    <dc:date>2022-03-23T18:28:20Z</dc:date>
    <item>
      <title>How do you assign a variable from a list to a row in a data table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/469959#M71401</link>
      <description>&lt;P&gt;I am working with a data table that has variable number of rows. I want to assign a categorical description that I will define to a new column called 'Reason 1'. This 'Reason 1' column will be assigned when the 'Name' column matches any of the strings in any of the lists that I have defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'Name' row entry will match exactly with an entry in the ::slitter, ::label, or ::case lists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to assign the different reason 1 codes to all rows and then analyze the data according to each Reason 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 &amp;lt;&amp;lt; New Column("Reason 1", Character, "Nominal");

Nrows = N Rows(dt1);

For( i =1, i&amp;lt;=Nrows, i++
		For( j=1, j&amp;lt;= N items( ::slitter ), j++,
		If(:Name(i) == Eval(slitter(j)), :Reason 1(i) = "Slitter");
		);
	);


// %Slitter% description codes
slitter = {"TM2300-370",
"TM2300-380",
"TM2300-385",
"TM2300-390",
"TM2300-395",
"TM2300-400"};&lt;BR /&gt;&lt;BR /&gt;// %Label% description codes (8)&lt;BR /&gt;::label = {"TM2300-020",&lt;BR /&gt;"TM2300-025",&lt;BR /&gt;"TM2300-070",&lt;BR /&gt;"TM2300-075",&lt;BR /&gt;"TM2300-080",&lt;BR /&gt;"TM2300-085",&lt;BR /&gt;"TM2300-090",&lt;BR /&gt;"TM2300-095"};&lt;BR /&gt;&lt;BR /&gt;//%Case% description codes (7)&lt;BR /&gt;::case = {"TM2300-030",&lt;BR /&gt;"TM2300-035",&lt;BR /&gt;"TM2300-040",&lt;BR /&gt;"TM2300-045",&lt;BR /&gt;"TM2300-050",&lt;BR /&gt;"TM2300-055",&lt;BR /&gt;"TM2300-060"};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:45:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/469959#M71401</guid>
      <dc:creator>gable64</dc:creator>
      <dc:date>2023-06-10T23:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you assign a variable from a list to a row in a data table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/470005#M71402</link>
      <description>&lt;P&gt;You have a couple of syntax errors, and an inefficient For loop to check for matches that can be replaced by using a Contains() function.&amp;nbsp; I have also added a method for creating the new formula column to do the same calculation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt1=current data table();
dt1 &amp;lt;&amp;lt; New Column( "Reason 1", Character, "Nominal" );

// %Slitter% description codes
slitter = {"TM2300-370", "TM2300-380", "TM2300-385", "TM2300-390", "TM2300-395", "TM2300-400"};

Nrows = N Rows( dt1 );

For( i = 1, i &amp;lt;= Nrows, i++,
	If( Contains( slitter, :Name[i] ) == 1,
		:Reason 1[i] = "Slitter"
	)
);

// or
dt1 &amp;lt;&amp;lt; New Column( "Reason 2",
	character,
	formula(
		If( Row() == 1,
			slitter = {"TM2300-370", "TM2300-380", "TM2300-385", "TM2300-390", "TM2300-395", "TM2300-400"}
		);
		If( Contains( slitter, :Name ) == 1,
			:Reason 2 = "Slitter"
		);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 20:57:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/470005#M71402</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-03-15T20:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do you assign a variable from a list to a row in a data table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/470259#M71434</link>
      <description>&lt;P&gt;There's another way that uses get rows where and contains.&amp;nbsp; No loop required.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = data table("Sample Data Set-1");

// %Slitter% description codes
slitter = {"TM2300-370", "TM2300-380", "TM2300-385", "TM2300-390", "TM2300-395", "TM2300-400"};

match_rows = dt &amp;lt;&amp;lt; get rows where(contains(slitter, :Name));

dt:Reason 1[match_rows] = "Slitter";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Mar 2022 13:14:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/470259#M71434</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2022-03-16T13:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you assign a variable from a list to a row in a data table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/472436#M71712</link>
      <description>&lt;P&gt;My mind initially went to a loop to complete what I wanted to do, but thank you for this alternative solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This categorized my data exactly like I wanted.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 18:28:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/472436#M71712</guid>
      <dc:creator>gable64</dc:creator>
      <dc:date>2022-03-23T18:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do you assign a variable from a list to a row in a data table?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/472437#M71713</link>
      <description>&lt;P&gt;For whatever reason, the loop was not assigning the variable to one particular list out of 5 lists I wanted to assign. The 'Get rows where' function accomplished what I wanted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for spending time on this solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Logan&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 18:30:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-you-assign-a-variable-from-a-list-to-a-row-in-a-data/m-p/472437#M71713</guid>
      <dc:creator>gable64</dc:creator>
      <dc:date>2022-03-23T18:30:40Z</dc:date>
    </item>
  </channel>
</rss>

