cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
%3CLINGO-SUB%20id%3D%22lingo-sub-5088%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EConvalida%20il%20nome%20della%20colonna%20esiste%20prima%20della%20rappresentazione%20grafica%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5088%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CP%3ECiao%2C%20sto%20cercando%20di%20convalidare%20che%20una%20tabella%20di%20dati%20contenga%20un%20determinato%20nome%20di%20colonna%20prima%20di%20creare%20grafici%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Ehanome1%20%3D%200%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20for%20(colval%20%3D%3D%201%2C%20colval%20%26lt%3B%3D%20Ncols(dt)%2C%20colval%2B%2B%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20colName%20%3D%20Nome%20colonna%20(colval)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20if%20(%20colName%20%3D%3D%20%22nome1%22%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20hasname1%20%3D%201%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20se%20(hanome1%20%3D%3D%201%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20%2F%2Fcrea%20grafico%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20)%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ETuttavia%2C%20il%20confronto%20non%20restituisce%20mai%20true%20perch%C3%A9%20%22nome1%22%20%C3%A8%20un%20tipo%20di%20dati%20stringa%20e%20il%20nome%20della%20colonna%20restituito%20da%3CSTRONG%3E%20Nome%20colonna%20(colval)%3C%2FSTRONG%3E%20%C3%A8%20un%20altro%20tipo%20di%20dati.%3C%2FP%3E%3CP%3ECome%20posso%20ottenere%20un%20valore%20di%20stringa%20da%20un%20nome%20di%20colonna%20per%20effettuare%20un%20confronto%20di%20stringhe%20valido%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EGrazie!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Convalida%20il%20nome%20della%20colonna%20esiste%20prima%20della%20rappresentazione%20grafica%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EFunziona%2C%20ottimo%20e%20molto%20pi%C3%B9%20breve%20di%20quello%20che%20stavo%20facendo.Grazie.%3CSPAN%20__jive_emoticon_name%3D%22grin%22%20__jive_macro_name%3D%22emoticon%22%20class%3D%22jive_macro%20jive_macro_emoticon%20jive_emote%22%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2F5.0.2%2Fimages%2Femoticons%2Fgrin.gif%22%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Convalida%20il%20nome%20della%20colonna%20esiste%20prima%20della%20rappresentazione%20grafica%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPuoi%20usare%20dt%20%26lt%3B%26lt%3B%20get%20column%20names(string)%3B%20per%20ottenere%20i%20nomi%20delle%20colonne%20come%20una%20stringa%20anzich%C3%A9%20come%20un%20oggetto%20colonna.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EProva%20questa%20singola%20riga%20di%20codice.%20Dovrebbe%20assegnare%201%20o%200%20a%20hasname1.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin%3A%200.0px%200.0px%200.0px%200.0px%3B%22%3Ehanome1%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%3D%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%232400eb%3B%22%3E%20Contiene%3C%2FSPAN%3E%3CSTRONG%3E%20(%3C%2FSTRONG%3E%20dt%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%26lt%3B%26lt%3B%3C%2FSPAN%3E%20ottenere%20i%20nomi%20delle%20colonne%3CSTRONG%3E%20(%3C%2FSTRONG%3E%20corda%3CSTRONG%3E%20)%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%2C%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23a40095%3B%22%3E%20%22nome1%22%3C%2FSPAN%3E%3CSTRONG%3E%20)%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin%3A%200.0px%200.0px%200.0px%200.0px%3B%22%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22margin%3A%200.0px%200.0px%200.0px%200.0px%3B%22%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
senatorx
Level III

Validate column name exists before graphing

Hi,  I am trying to validate that a data table contains a certain column name prior to creating graphs:

hasname1 = 0;
     for (colval == 1, colval <= Ncols(dt), colval++,
           colName = Column Name(colval);
           if ( colName == "name1",
                 hasname1 = 1;

           );
if (hasname1 == 1,
      //create graph
);

However, the comparison never returns true because "name1" is a string data type, and the column name returned from Column Name(colval) is some other data type.

How can I get a string value from a Column Name to make a valid string comparison?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Validate column name exists before graphing

You can use dt << get column names(string); to get column names as a string instead of a column object.

Try this single line of code. Should assign 1 or 0 to hasname1.

hasname1 = Contains( dt << get column names( string ), "name1" );



View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Validate column name exists before graphing

You can use dt << get column names(string); to get column names as a string instead of a column object.

Try this single line of code. Should assign 1 or 0 to hasname1.

hasname1 = Contains( dt << get column names( string ), "name1" );



senatorx
Level III

Re: Validate column name exists before graphing

Works, great, and much shorter than what I was doing.  Thank you.