cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-46404%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%EC%97%AC%EB%9F%AC%20%EC%A1%B0%EA%B1%B4%EC%97%90%20%EB%94%B0%EB%9D%BC%20%ED%96%89%20%EC%84%A0%ED%83%9D%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-46404%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CDIV%20class%3D%22lia-message-template-problem-zone%22%3E%0A%3CH2%20id%3D%22toc-hId--1330392682%22%20id%3D%22toc-hId-1620812988%22%20id%3D%22toc-hId-1620812988%22%3E%EB%AC%B8%EC%A0%9C%3C%2FH2%3E%0A%3CP%3E%EB%91%98%20%EC%9D%B4%EC%83%81%EC%9D%98%20%EC%A1%B0%EA%B1%B4%EC%9D%84%20%EC%B6%A9%EC%A1%B1%ED%95%98%EB%8A%94%20%EB%8D%B0%EC%9D%B4%ED%84%B0%20%ED%85%8C%EC%9D%B4%EB%B8%94%EC%9D%98%20%ED%96%89%EC%9D%84%20%EC%84%A0%ED%83%9D%ED%95%98%EB%A0%A4%EA%B3%A0%20%ED%95%9C%EB%8B%A4%EA%B3%A0%20%EA%B0%80%EC%A0%95%ED%95%A9%EB%8B%88%EB%8B%A4.%20%EB%98%90%EB%8A%94%20%EB%AA%87%20%EA%B0%80%EC%A7%80%20%EC%A1%B0%EA%B1%B4%20%EC%A4%91%20%ED%95%98%EB%82%98%EB%A5%BC%20%EC%B6%A9%EC%A1%B1%ED%95%98%EB%8A%94%20%ED%96%89%EC%9D%84%20%EC%84%A0%ED%83%9D%ED%95%98%EB%A0%A4%EA%B3%A0%20%ED%95%A0%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%0A%3CH2%20id%3D%22toc-hId--442889001%22%20id%3D%22toc-hId--931343973%22%20id%3D%22toc-hId--931343973%22%3E%ED%95%B4%EA%B2%B0%EC%B1%85%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3E%EB%8B%A4%EC%9D%8C%20%EC%98%88%EB%8A%94%20Select%20Where%20%EB%A9%94%EC%8B%9C%EC%A7%80%EC%99%80%20%ED%95%A8%EA%BB%98%20%EB%85%BC%EB%A6%AC%EC%A0%81%20AND(%26amp%3B)%20%EB%B0%8F%20OR(%7C)%20%EC%97%B0%EC%82%B0%EC%9E%90%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%97%AC%EB%9F%AC%20%EC%A1%B0%EA%B1%B4%EC%9D%84%20%EC%B6%A9%EC%A1%B1%ED%95%98%EB%8A%94%20%ED%96%89%EC%9D%84%20%EC%84%A0%ED%83%9D%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%84%20%EB%B3%B4%EC%97%AC%EC%A4%8D%EB%8B%88%EB%8B%A4.%EC%9E%90%EC%84%B8%ED%95%9C%20%EB%82%B4%EC%9A%A9%EC%9D%80%20%ED%8F%AC%ED%95%A8%EB%90%9C%20%EC%A3%BC%EC%84%9D%EC%9D%84%20%EC%B0%B8%EC%A1%B0%ED%95%98%EC%8B%AD%EC%8B%9C%EC%98%A4.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F*%20Open%20a%20sample%20data%20table%20*%2F%0Adt%20%3D%20Open(%20%22%24SAMPLE_DATA%5CBig%20Class.jmp%22%20)%3B%0A%0A%2F*%20Select%20rows%20where%20students%20are%20over%2013%2C%20who%20are%20also%20less%20than%2065%20inches%20tall%20*%2F%0Adt%20%26lt%3B%26lt%3B%20Select%20Where(%20%3Aage%20%26gt%3B%2013%20%26amp%3B%20%3Aheight%20%26lt%3B%2065%20)%3B%0A%0AWait(%202%20)%3B%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20For%20demonstration%20purposes%0A%0A%2F*%20Select%20rows%20where%20students%20are%20either%2012%20or%2014%20years%20old%20*%2F%0Adt%20%26lt%3B%26lt%3B%20Select%20Where(%20%3Aage%20%3D%3D%2012%20%7C%20%3Aage%20%3D%3D%2014%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-solution-zone%22%3E%0A%3CH2%20id%3D%22toc-hId-444614680%22%20id%3D%22toc-hId-811466362%22%20id%3D%22toc-hId-811466362%22%3E%EB%85%BC%EC%9D%98%3C%2FH2%3E%0A%3CP%3ESelect%20Where()%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%8D%94%20%EB%A7%8E%EC%9D%80%20%EC%98%88%EB%8A%94%20%EB%8B%A4%EC%9D%8C%EC%97%90%EC%84%9C%20%EC%B0%BE%EC%9D%84%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%3CA%20href%3D%22http%3A%2F%2Fwww.jmp.com%2Fsupport%2Fhelp%2F13-2%2FSelect_Rows_2.shtml%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%20%ED%96%89%20%EC%84%A0%ED%83%9D%3C%2FA%3E%20JMP%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8C%85%20%EA%B0%80%EC%9D%B4%EB%93%9C%EC%9D%98%20%EC%84%B9%EC%85%98%EC%9D%84%20%EC%B0%B8%EC%A1%B0%ED%95%98%EC%8B%AD%EC%8B%9C%EC%98%A4.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1332118361%22%20id%3D%22toc-hId--1740690599%22%20id%3D%22toc-hId--1740690599%22%3E%EB%98%90%ED%95%9C%EB%B3%B4%EC%8B%AD%EC%8B%9C%EC%98%A4%3C%2FH2%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJSL-Cookbook%2FSelect-rows-from-the-currently-selected-rows%2Fta-p%2F46409%22%20target%3D%22_self%22%3E%ED%98%84%EC%9E%AC%20%EC%84%A0%ED%83%9D%EB%90%9C%20%ED%96%89%EC%97%90%EC%84%9C%20%ED%96%89%20%EC%84%A0%ED%83%9D%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJSL-Cookbook%2FSelect-rows-that-match-any-value-in-a-list%2Fta-p%2F46411%22%20target%3D%22_blank%22%3E%EB%AA%A9%EB%A1%9D%EC%9D%98%20%EA%B0%92%EA%B3%BC%20%EC%9D%BC%EC%B9%98%ED%95%98%EB%8A%94%20%ED%96%89%20%EC%84%A0%ED%83%9D%3C%2FA%3E%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-221566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EC%97%AC%EB%9F%AC%20%EC%A1%B0%EA%B1%B4%EC%97%90%20%EB%94%B0%EB%9D%BC%20%ED%96%89%EC%9D%84%20%EC%84%A0%ED%83%9D%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-221566%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15586%22%20target%3D%22_blank%22%3E%40rishdude23%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%EC%97%B4%20%EC%88%98%EC%8B%9D%EC%9D%80%20%EA%B8%B0%EB%B3%B8%EC%A0%81%EC%9C%BC%EB%A1%9C%20%ED%96%89%EC%9D%84%20%EB%B0%98%EB%B3%B5%ED%95%A9%EB%8B%88%EB%8B%A4.%EB%94%B0%EB%9D%BC%EC%84%9C%20For()%20%EB%A3%A8%ED%94%84%EA%B0%80%20%ED%95%84%EC%9A%94%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.Lag()%20%ED%95%A8%EC%88%98%EB%8A%94%20%EC%9D%B4%EC%A0%84%20%ED%96%89%EC%9D%98%20%EC%9D%B8%EC%88%98%20%EA%B0%92%EC%9D%84%20%EB%B0%98%ED%99%98%ED%95%A9%EB%8B%88%EB%8B%A4.%EA%B7%B8%EB%9E%98%EC%84%9C%20%EC%9D%B4%EC%99%80%20%EA%B0%99%EC%9D%80%20%EA%B2%83%EC%9D%B4%20%EB%8B%B9%EC%8B%A0%EC%97%90%EA%B2%8C%20%EB%8F%84%EC%9B%80%EC%9D%B4%20%EB%90%A0%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%20Formula(%0A%20%20If(%0A%20%20%20(%3Aage%20%3D%3D%20Lag(%20%3Aage%2C%201%20))%20%26amp%3B%20(%3Asex%20%3D%3D%20Lag(%20%3Asex%2C%201%20))%2C%20%22Same%20age%2C%20same%20gender%22%2C%0A%20%20%20(%3Aage%20!%3D%20Lag(%20%3Aage%2C%201%20))%20%26amp%3B%20(%3Asex%20%3D%3D%20Lag(%20%3Asex%2C%201%20))%2C%20%22Diff%20age%2C%20same%20gender%22%2C%0A%20%20%20(%3Aage%20%3D%3D%20Lag(%20%3Aage%2C%201%20))%20%26amp%3B%20(%3Asex%20!%3D%20Lag(%20%3Asex%2C%201%20))%2C%20%22Same%20age%2C%20diff%20gender%22%2C%0A%20%20%20(%3Aage%20!%3D%20Lag(%20%3Aage%2C%201%20))%20%26amp%3B%20(%3Asex%20!%3D%20Lag(%20%3Asex%2C%201%20))%2C%20%22Diff%20age%2C%20diff%20gender%22%0A%20%20)%0A%20)%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%EB%8F%84%EC%9B%80%EC%9D%B4%20%EB%90%98%EA%B8%B8%20%EB%B0%94%EB%9E%8D%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%EC%9D%B4%20%EC%A7%88%EB%AC%B8%EC%9D%80%20Select%20Where()%20%EC%82%AC%EC%9A%A9%EA%B3%BC%20%EA%B4%80%EB%A0%A8%EC%9D%B4%20%EC%97%86%EC%A7%80%EB%A7%8C%20%EC%97%B4%20%EC%88%98%EC%8B%9D%EA%B3%BC%20%EA%B4%80%EB%A0%A8%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4.%EC%9D%B4%EC%99%80%20%EA%B0%99%EC%9D%80%20%EC%A7%88%EB%AC%B8%EC%9D%80%20%EB%A7%8E%EC%9D%80%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%84%B0%EA%B0%80%20%EC%9D%91%EB%8B%B5%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%8A%94%20%EC%9D%BC%EB%B0%98%20%ED%86%A0%EB%A1%A0%20%EC%98%81%EC%97%AD%EC%9C%BC%EB%A1%9C%20%EC%97%B0%EA%B2%B0%ED%95%98%EB%8A%94%20%EA%B2%83%EC%9D%B4%20%EC%A2%8B%EC%8A%B5%EB%8B%88%EB%8B%A4.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-221564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%EC%97%AC%EB%9F%AC%20%EC%A1%B0%EA%B1%B4%EC%97%90%20%EB%94%B0%EB%9D%BC%20%ED%96%89%EC%9D%84%20%EC%84%A0%ED%83%9D%ED%95%A9%EB%8B%88%EB%8B%A4.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-221564%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5579%22%20target%3D%22_blank%22%3E%40Wendy_Murphrey%3C%2FA%3E%3C%2FP%3E%3CP%3E%EC%95%88%EB%85%95%2C%3C%2FP%3E%3CP%3Efor%20long%20%EB%B0%8F%20%EB%AA%87%20%EA%B0%80%EC%A7%80%20%EC%A1%B0%EA%B1%B4%EC%9D%84%20%ED%8F%AC%ED%95%A8%ED%95%98%EB%8A%94%20%EC%88%98%EC%8B%9D%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%22AgeSex_comp%22%EB%9D%BC%EB%8A%94%20%EB%B9%85%20%EB%8D%B0%EC%9D%B4%ED%84%B0%20jmp%20%ED%8C%8C%EC%9D%BC%EC%97%90%20%EC%83%88%20%EC%97%B4%EC%9D%84%20%EC%93%B0%EB%A0%A4%EA%B3%A0%20%ED%95%A9%EB%8B%88%EB%8B%A4.%20%EC%9D%B4%EC%A0%84%20%ED%96%89%EC%9D%98%20%EC%97%B0%EB%A0%B9%20%EB%B0%8F%20%EC%84%B1%EB%B3%84%20%EC%A0%95%EB%B3%B4%EB%A5%BC%20%EB%8B%A4%EC%9D%8C%20%ED%96%89%EA%B3%BC%20%EB%B9%84%EA%B5%90%ED%95%98%EC%97%AC%20%EA%B0%99%EC%9D%80%EC%A7%80%20%EB%8B%A4%EB%A5%B8%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EA%B3%A0%20%EC%8B%B6%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%8B%A4%EC%9D%8C%EC%9D%80%20%EB%82%B4%EA%B0%80%20%EC%9E%91%EC%84%B1%ED%95%9C%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%9E%85%EB%8B%88%EB%8B%A4.%20%EC%9E%91%EB%8F%99%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.%20%EB%82%B4%EA%B0%80%20%EC%9E%98%EB%AA%BB%20%EA%B0%80%EA%B3%A0%EC%9E%88%EB%8A%94%20%EC%95%84%EC%9D%B4%EB%94%94%EC%96%B4%EA%B0%80%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%20%3D%20current%20data%20table()%3B%0A%0Adt%20%26lt%3B%26lt%3B%20NewColumn(%22AgeSex_Comp%22%2C%20Character%2C%20Nominal%2C%20Formula(%0A%20FOR(i%3D1%2C%20i%26lt%3B%3D%20N%20Row(dt)%2C%20i%2B%2B%2C%0A%20%20if((%3Aage%5BRow(i)%5D%20%3D%3D%20%3Aage%5BRow(i%2B1)%5D)%20%26amp%3B%20(%3Asex%5BRow(i)%5D%20%3D%3D%20%3Asex%5BRow(i%2B1)%5D)%2C%22Same%20age%2C%20same%20gender%22%2C%20%0A%20%20%20%20%20(%3Aage%5BRow(i)%5D%20!%3D%20%3Aage%5BRow(i%2B1)%5D)%20%26amp%3B%20(%3Asex%5BRow(i)%5D%20%3D%3D%20%3Asex%5BRow(i%2B1)%5D)%2C%22Diff%20age%2C%20same%20gender%22%2C%20%0A%20%20%20%20%20(%3Aage%5BRow(i)%5D%20%3D%3D%20%3Aage%5BRow(i%2B1)%5D)%20%26amp%3B%20(%3Asex%5BRow(i)%5D%20!%3D%20%3Asex%5BRow(i%2B1)%5D)%2C%22Same%20age%2C%20diff%20gender%22%2C%0A%20%20%20%20%20(%3Aage%5BRow(i)%5D%20!%3D%20%3Aage%5BRow(i%2B1)%5D)%20%26amp%3B%20(%3Asex%5BRow(i)%5D%20!%3D%20%3Asex%5BRow(i%2B1)%5D)%2C%22Diff%20age%2C%20diff%20gender%22%0A%20)%0A%20)%0A)%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Select rows based upon multiple conditions

Problem

Suppose you wish to select rows in a data table that meet more than one condition. Or, maybe you want to select the rows that meet one of a few conditions.  

Solution

The following examples demonstrate how you can use the logical AND (&) and OR (|) operators with the Select Where message to select rows that meet multiple conditions.  See the embedded comments for details. 

 

/* Open a sample data table */
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

/* Select rows where students are over 13, who are also less than 65 inches tall */
dt << Select Where( :age > 13 & :height < 65 );

Wait( 2 );           // For demonstration purposes

/* Select rows where students are either 12 or 14 years old */
dt << Select Where( :age == 12 | :age == 14 );

 

 

Discussion

Many more examples of using Select Where() can be found in the Select Rows section of the JMP Scripting Guide.

See Also

Select rows from the currently selected rows

Select rows that match any value in a list

Comments
rishdude23

@Wendy_Murphrey 

Hi, 

I am trying to write a New Column to the Big Data jmp file called "AgeSex_comp" with a formula containing a for long and a few conditions. I would like to compare the previous row's age and gender information with the next row to see whether they are the same or different. Here is the Script that I wrote, it does not work. Any ideas where I am going wrong?

dt  = current data table();

dt << NewColumn("AgeSex_Comp", Character, Nominal, Formula(
	FOR(i=1, i<= N Row(dt), i++,
		if((:age[Row(i)] == :age[Row(i+1)]) & (:sex[Row(i)] == :sex[Row(i+1)]),"Same age, same gender", 
		   (:age[Row(i)] != :age[Row(i+1)]) & (:sex[Row(i)] == :sex[Row(i+1)]),"Diff age, same gender", 
		   (:age[Row(i)] == :age[Row(i+1)]) & (:sex[Row(i)] != :sex[Row(i+1)]),"Same age, diff gender",
		   (:age[Row(i)] != :age[Row(i+1)]) & (:sex[Row(i)] != :sex[Row(i+1)]),"Diff age, diff gender"
	)
	)
)
)

 

@rishdude23 

 

A column formula natively iterates over the rows.  Therefore, the For() loop is unnecessary.  The Lag() function will return the value of the argument in the previous row.  So something like this might work for you.

 

 

	Formula(
		If(
			(:age == Lag( :age, 1 )) & (:sex == Lag( :sex, 1 )), "Same age, same gender",
			(:age != Lag( :age, 1 )) & (:sex == Lag( :sex, 1 )), "Diff age, same gender",
			(:age == Lag( :age, 1 )) & (:sex != Lag( :sex, 1 )), "Same age, diff gender",
			(:age != Lag( :age, 1 )) & (:sex != Lag( :sex, 1 )), "Diff age, diff gender"
		)
	)

Hope that helps.

 

This question is not related to using Select Where() but rather a column formula.  Questions such as this are better directed to the general Discussions area where many scripters can respond.

 

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.