cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-49999%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Epas%20%C3%A9gal%20au%20symbole%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-49999%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESalut%2C%3C%2FP%3E%0A%3CP%3EJ'ai%20le%20script%20suivant%20et%20il%20ne%20s%C3%A9lectionne%20pas%20les%20noms%20de%20colonnes%20corrects%20(%22Std%22).%20Voici%20le%20sc%C3%A9nario%26nbsp%3B%3A%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ecols%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20column%20Names()%3B%0A%20%0Afor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20cols%20)%2C%20i%2B%2B%2C%0Aif(%20contains(%20cols%5Bi%5D%20%2C%20%22Std%22)%20%20!%3D%201%0A%2C%0AColumn(%20dt%2C%20cols%5Bi%5D%20)%20%26lt%3B%26lt%3B%20Set%20Data%20Type(%20%22Character%22%20)%3B%0AColumn(%20dt%2C%20cols%5Bi%5D%20)%20%26lt%3B%26lt%3B%20Set%20Modeling%20Type%20(%22Nominal%22)%0A)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22p1%22%3EOn%20dirait%20que%20!%3D%20ne%20fait%20pas%20le%20travail.%20Toute%20aide%20%C3%A0%20ce%20sujet%3F%20Merci%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-50006%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20pas%20%C3%A9gal%20au%20symbole%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50006%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMerci%20beaucoup%20pour%20l'aide%20rapide.%20Remplacer%201%20par%200%20fonctionne%20parfaitement.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-50001%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20pas%20%C3%A9gal%20au%20symbole%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50001%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20fa%C3%A7on%20dont%20je%20lis%20votre%20script%2C%20cela%20ne%20changera%20que%20les%20donn%C3%A9es%20et%20le%20type%20de%20mod%C3%A9lisation%20pour%20les%20colonnes%20qui%3CSTRONG%3E%20imm%C3%A9diatement%3C%2FSTRONG%3E%20commencer%20par%20%C2%AB%26nbsp%3BStd%26nbsp%3B%C2%BB%20(par%20exemple%2C%20une%20colonne%20nomm%C3%A9e%20%C2%AB%26nbsp%3BStd%20Dev%26nbsp%3B%C2%BB%20serait%20modifi%C3%A9e%2C%20mais%20pas%20une%20colonne%20nomm%C3%A9e%20%C2%AB%26nbsp%3BCol%20Std%26nbsp%3B%C2%BB).%3C%2FP%3E%3CP%3EContient()%20renvoie%20la%20position%20dans%20la%20cha%C3%AEne%20de%20la%20sous-cha%C3%AEne%20que%20vous%20avez%20sp%C3%A9cifi%C3%A9e.Si%20cols%5Bi%5D%20%3D%20%22Std%20Dev%22%2C%20Contient(cols%5Bi%5D%2C%22Std%22)%20renverra%20la%20valeur%201.%20Si%20cols%5Bi%5D%20%3D%20%22Col%20Std%22%2C%20alors%20Contient(cols%5Bi%5D%2C%20%22Std%22%20)%20renverra%20la%20valeur%205%20car%20%22Std%22%20commence%20par%20le%205%C3%A8me%20caract%C3%A8re%20de%20la%20cha%C3%AEne.Ce%20n'est%20que%20si%20j'essaie%20un%20nom%20de%20colonne%20qui%20n'a%20pas%20le%20%22Std%22%20dans%20le%20nom%20que%20Contient()%20renverra%200.%3C%2FP%3E%3CP%3EContient(cols%5Bi%5D%2C%20%22Std%22)%26nbsp%3B!%3D%201%20renverra%20vrai%20pour%20tous%20les%20noms%20de%20colonnes%20qui%20ne%20commencent%20pas%20imm%C3%A9diatement%20par%20%22Std%22.%3C%2FP%3E%3CP%3ETypiquement%2C%20la%20fa%C3%A7on%20d'utiliser%20Contient()%20pour%20d%C3%A9terminer%20si%20une%20sous-cha%C3%AEne%20est%20contenue%20dans%20une%20cha%C3%AEne%20serait%20d'utiliser%20%22!%3D0%22%20ou%20%22%26gt%3B0%22.Changez%20le%201%20en%200%20et%20voyez%20si%20cela%20fonctionne.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
AT
AT
Level V

not equal to symbol

Hi,

I have the following script and it does not select the correct columns names ("Std"). Here is the script:

 

cols = dt << Get column Names();
 
for( i = 1, i <= N Items( cols ), i++,
if( contains( cols[i] , "Std")  != 1
,
Column( dt, cols[i] ) << Set Data Type( "Character" );
Column( dt, cols[i] ) << Set Modeling Type ("Nominal")
)
);

 

 

Looks like != does not do the job. Any help on this? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
AT
AT
Level V

Re: not equal to symbol

Thanks so much for quick help. Replacing 1 by 0 works perfectly.

View solution in original post

2 REPLIES 2
cwillden
Super User (Alumni)

Re: not equal to symbol

The way I read your script, it will only change the data and modeling type for columns that immediately start with "Std" (e.g. a column named "Std Dev" would be modified, but a column named "Col Std" would not).

Contains() returns the position in the string of the substring you specified.  If cols[i] = "Std Dev", Contains(cols[i],"Std") will return the value 1.  If cols[i] = "Col Std", then Contains(cols[i], "Std") will return the value 5 because that "Std" starts with the 5th character in the string.  Only if I try a column name that doesn't have the "Std" in the name will Contains() return 0.

Contains(cols[i], "Std")  != 1 will return true for all columns names that don't immediately start with "Std".

Typically, the way to use Contains() to determine if a substring is contained within a string would be to use either "!=0" or ">0".  Switch the 1 to a 0 and see if that works.

-- Cameron Willden
AT
AT
Level V

Re: not equal to symbol

Thanks so much for quick help. Replacing 1 by 0 works perfectly.

Recommended Articles