topic Re: If row column value equals any values of any array then... What is the general form of this formal? in Discussions
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195025#M41596
<P>Thanks.</P><P>I'm trying to do something like this. </P><P>#1 it expects a numeric.</P><P>#2 the return is coming back all missing values. I tried data type expression and numeric, couldn't run distribution to see if there were values other than missing value.</P><PRE><CODE class=" language-jsl">cust = ["customer1","customer2","customer3"];
If( Loc( As List( cust ), :Name( "Ship-To Customer" ) ),
1,
0
);</CODE></PRE><P>//update 4/26/19<BR />the orignal post did not have cust defined, instead it showed</P><P><CODE class=" language-jsl">z = ["customer1","customer2","customer3"];</CODE></P><P>That's why TXNelson is asking what is "cust"?</P><P> </P>Fri, 26 Apr 2019 14:37:53 GMTBSwid2019-04-26T14:37:53ZIf row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195008#M41591
<P>How do I write an If statement (or whatever the right function is) to evaluated when a row's column value = any value in an array?<BR /><BR />Example:</P><P>If( :ColToCheck == [Any of these values] , then 1, else 0 )</P>Thu, 25 Apr 2019 18:59:09 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195008#M41591BSwid2019-04-25T18:59:09ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195020#M41592
<P>Use the Loc() function to check to see if any values are the same in a list when compared. When doing this with a matrix, convert the matrix to a list.</P>
<PRE><CODE class=" language-jsl">z=[1,2,3,4];
loc(as list(z),2);</CODE></PRE>Thu, 25 Apr 2019 19:24:08 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195020#M41592txnelson2019-04-25T19:24:08ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195025#M41596
<P>Thanks.</P><P>I'm trying to do something like this. </P><P>#1 it expects a numeric.</P><P>#2 the return is coming back all missing values. I tried data type expression and numeric, couldn't run distribution to see if there were values other than missing value.</P><PRE><CODE class=" language-jsl">cust = ["customer1","customer2","customer3"];
If( Loc( As List( cust ), :Name( "Ship-To Customer" ) ),
1,
0
);</CODE></PRE><P>//update 4/26/19<BR />the orignal post did not have cust defined, instead it showed</P><P><CODE class=" language-jsl">z = ["customer1","customer2","customer3"];</CODE></P><P>That's why TXNelson is asking what is "cust"?</P><P> </P>Fri, 26 Apr 2019 14:37:53 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195025#M41596BSwid2019-04-26T14:37:53ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195026#M41597
<P>1. A matrix can only contain numeric values. Therefore, the matrix z needs to be specified as a List, not as a Matrix</P>
<P>2. I do not know what "cust" is.</P>
<P>3. Is this a column formula, or open JSL code?</P>
<P>4. Loc returns a matrix of the positions where the testing value is found in the List. Therefore, you need to determine if more than 0 rows were returned to determine if a match has been found.</P>
<P> </P>
<P>Below are a couple of script examples that might help you out</P>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
dt = Current Data Table();
// As a formula in a new column
dt << New Column( "is present",
formula(
z = {"customer1", "customer2", "customer3"};
If( N Rows( Loc( z, :Name( "Ship-To Customer" ) ) > 0 ),
1,
0
);
)
);
// In open JSL
z = {"customer1", "customer2", "customer3"};
For( i = 1, i <= N Rows( dt ), i++,
If( N Rows( Loc( z, :Name( "Ship-To Customer" )[i] ) ) > 0,
1,
0
);
);</CODE></PRE>Thu, 25 Apr 2019 21:02:39 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195026#M41597txnelson2019-04-25T21:02:39ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195049#M41598
<PRE><CODE class=" language-jsl">Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt << new Column("Some Check", FOrmula(
//only doing !! so it's negates the output of contains (which is WHERE it is in the list)
!!Contains({59, 63, 48, 70}, :height)
));</CODE></PRE>Thu, 25 Apr 2019 23:01:11 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195049#M41598vince_faller2019-04-25T23:01:11ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195141#M41602
<P>Thank you both. <LI-USER uid="2687"></LI-USER> TX got me over the hump last night. I just converted characters to numeric and it gave the desired result.<BR /><BR />I think <LI-USER uid="2610"></LI-USER> 's solution is what I'm looking for. I tried it with characters and it worked</P><P> </P><PRE><CODE class=" language-jsl"> New Column( "Some Check 2",
Numeric,
"Continuous",
Format( "Best", 12 ),<BR /> Formula( !!Contains( {"TIM", "ALICE", "JANE", "UDY"}, :name ) )
),<BR /> // "UDY" is in there to verify contains will not return true for "JUDY"<BR /></CODE></PRE>Fri, 26 Apr 2019 14:35:52 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195141#M41602BSwid2019-04-26T14:35:52ZRe: If row column value equals any values of any array then... What is the general form of this formal?
https://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195143#M41603
<P>Not directly.......that is why I use Loc().</P>Fri, 26 Apr 2019 14:14:10 GMThttps://community.jmp.com/t5/Discussions/If-row-column-value-equals-any-values-of-any-array-then-What-is/m-p/195143#M41603txnelson2019-04-26T14:14:10Z