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%3EValide%20que%20el%20nombre%20de%20la%20columna%20exista%20antes%20de%20graficar%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%3EHola%2C%20estoy%20tratando%20de%20validar%20que%20una%20tabla%20de%20datos%20contenga%20un%20determinado%20nombre%20de%20columna%20antes%20de%20crear%20gr%C3%A1ficos%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Etiene%20nombre1%20%3D%200%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20para%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%20Nombre%20de%20columna%20(colval)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20if%20(colName%20%3D%3D%20%22nombre1%22%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20tienenombre1%20%3D%201%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20si%20(tiene%20nombre1%20%3D%3D%201%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20%2F%2Fcrear%20grafo%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20)%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ESin%20embargo%2C%20la%20comparaci%C3%B3n%20nunca%20devuelve%20verdadero%20porque%20%22nombre1%22%20es%20un%20tipo%20de%20datos%20de%20cadena%20y%20el%20nombre%20de%20columna%20devuelto%20por%3CSTRONG%3E%20Nombre%20de%20la%20columna%20(colval)%3C%2FSTRONG%3E%20es%20alg%C3%BAn%20otro%20tipo%20de%20datos.%3C%2FP%3E%3CP%3E%C2%BFC%C3%B3mo%20puedo%20obtener%20un%20valor%20de%20cadena%20de%20un%20nombre%20de%20columna%20para%20hacer%20una%20comparaci%C3%B3n%20de%20cadena%20v%C3%A1lida%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%C2%A1Gracias!%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%20Validar%20que%20el%20nombre%20de%20la%20columna%20exista%20antes%20de%20graficar%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EFunciona%2C%20genial%2C%20y%20mucho%20m%C3%A1s%20corto%20de%20lo%20que%20estaba%20haciendo.Gracias.%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%20Validar%20que%20el%20nombre%20de%20la%20columna%20exista%20antes%20de%20graficar%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPuede%20usar%20dt%20%26lt%3B%26lt%3B%20obtener%20nombres%20de%20columna%20(cadena)%3B%20para%20obtener%20nombres%20de%20columna%20como%20una%20cadena%20en%20lugar%20de%20un%20objeto%20de%20columna.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EPruebe%20esta%20%C3%BAnica%20l%C3%ADnea%20de%20c%C3%B3digo.%20Debe%20asignar%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%3Etienenombre1%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%20obtener%20nombres%20de%20columna%3CSTRONG%3E%20(%3C%2FSTRONG%3E%20cuerda%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%22nombre1%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.