cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-46404%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ESeleziona%20le%20righe%20in%20base%20a%20pi%C3%B9%20condizioni%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-1620812985%22%20id%3D%22toc-hId-1620812985%22%3EProblema%3C%2FH2%3E%0A%3CP%3ESupponiamo%20di%20voler%20selezionare%20le%20righe%20in%20una%20tabella%20dati%20che%20soddisfano%20pi%C3%B9%20di%20una%20condizione.%20Oppure%20potresti%20voler%20selezionare%20le%20righe%20che%20soddisfano%20una%20delle%20poche%20condizioni.%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--931343976%22%20id%3D%22toc-hId--931343976%22%3ESoluzione%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3ENegli%20esempi%20seguenti%20viene%20illustrato%20come%20utilizzare%20gli%20operatori%20logici%20AND%20(%26amp%3B)%20e%20OR%20(%7C)%20con%20il%20messaggio%20Seleziona%20dove%20per%20selezionare%20righe%20che%20soddisfano%20pi%C3%B9%20condizioni.Vedi%20i%20commenti%20incorporati%20per%20i%20dettagli.%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-811466359%22%20id%3D%22toc-hId-811466359%22%3EDiscussione%3C%2FH2%3E%0A%3CP%3EMolti%20altri%20esempi%20di%20utilizzo%20di%20Select%20Where()%20possono%20essere%20trovati%20nel%20file%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%20Seleziona%20Righe%3C%2FA%3E%20sezione%20della%20Guida%20allo%20scripting%20JMP.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1332118361%22%20id%3D%22toc-hId--1740690602%22%20id%3D%22toc-hId--1740690602%22%3EGuarda%20anche%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%3ESeleziona%20le%20righe%20dalle%20righe%20attualmente%20selezionate%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%3ESeleziona%20le%20righe%20che%20corrispondono%20a%20qualsiasi%20valore%20in%20un%20elenco%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%3ERi%3A%20Selezionare%20le%20righe%20in%20base%20a%20pi%C3%B9%20condizioni%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%3EUna%20formula%20di%20colonna%20esegue%20nativamente%20l'iterazione%20sulle%20righe.Pertanto%2C%20il%20ciclo%20For()%20non%20%C3%A8%20necessario.La%20funzione%20Lag()%20restituir%C3%A0%20il%20valore%20dell'argomento%20nella%20riga%20precedente.Quindi%20qualcosa%20del%20genere%20potrebbe%20funzionare%20per%20te.%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%3ESpero%20che%20aiuti.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EQuesta%20domanda%20non%20%C3%A8%20correlata%20all'utilizzo%20di%20Select%20Where()%20ma%20piuttosto%20a%20una%20formula%20di%20colonna.Domande%20come%20questa%20sono%20meglio%20indirizzate%20all'area%20Discussioni%20generali%20dove%20molti%20scripter%20possono%20rispondere.%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%3ERi%3A%20Selezionare%20le%20righe%20in%20base%20a%20pi%C3%B9%20condizioni%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%3ECIAO%2C%3C%2FP%3E%3CP%3ESto%20provando%20a%20scrivere%20una%20nuova%20colonna%20nel%20file%20jmp%20Big%20Data%20chiamato%20%22AgeSex_comp%22%20con%20una%20formula%20contenente%20una%20formula%20lunga%20e%20alcune%20condizioni.%20Vorrei%20confrontare%20le%20informazioni%20su%20et%C3%A0%20e%20sesso%20della%20riga%20precedente%20con%20quelle%20della%20riga%20successiva%20per%20vedere%20se%20sono%20uguali%20o%20diverse.%20Ecco%20lo%20script%20che%20ho%20scritto%2C%20non%20funziona.%20Qualche%20idea%20su%20dove%20sbaglio%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.