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%3E%C3%9Cberpr%C3%BCfen%20Sie%2C%20ob%20der%20Spaltenname%20vor%20der%20grafischen%20Darstellung%20vorhanden%20ist%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%3EHallo%2C%20ich%20versuche%20zu%20validieren%2C%20dass%20eine%20Datentabelle%20einen%20bestimmten%20Spaltennamen%20enth%C3%A4lt%2C%20bevor%20ich%20Diagramme%20erstelle%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Ehasname1%20%3D%200%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20f%C3%BCr%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%20Spaltenname%20(colval)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20if%20(%20colName%20%3D%3D%20%22name1%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%20if%20(hasname1%20%3D%3D%201%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20%2F%2F%20Grafik%20erstellen%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20)%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EDer%20Vergleich%20gibt%20jedoch%20niemals%20%E2%80%9Etrue%E2%80%9C%20zur%C3%BCck%2C%20da%20%E2%80%9Ename1%E2%80%9C%20ein%20Zeichenfolgendatentyp%20ist%20und%20der%20Spaltenname%20von%20zur%C3%BCckgegeben%20wird%3CSTRONG%3E%20Spaltenname(colval)%3C%2FSTRONG%3E%20ein%20anderer%20Datentyp%20ist.%3C%2FP%3E%3CP%3EWie%20kann%20ich%20einen%20Zeichenfolgenwert%20aus%20einem%20Spaltennamen%20abrufen%2C%20um%20einen%20g%C3%BCltigen%20Zeichenfolgenvergleich%20durchzuf%C3%BChren%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EVielen%20Dank!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EBetreff%3A%20%C3%9Cberpr%C3%BCfen%20Sie%2C%20dass%20der%20Spaltenname%20vor%20der%20grafischen%20Darstellung%20existiert%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EFunktioniert%2C%20gro%C3%9Fartig%20und%20viel%20k%C3%BCrzer%20als%20das%2C%20was%20ich%20tat.Vielen%20Dank.%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%3EBetreff%3A%20%C3%9Cberpr%C3%BCfen%20Sie%2C%20dass%20der%20Spaltenname%20vor%20der%20grafischen%20Darstellung%20existiert%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESie%20k%C3%B6nnen%20dt%20%26lt%3B%26lt%3B%20Spaltennamen%20abrufen%20(Zeichenfolge)%20verwenden%3B%20um%20Spaltennamen%20als%20Zeichenfolge%20anstelle%20eines%20Spaltenobjekts%20zu%20erhalten.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EProbieren%20Sie%20diese%20einzelne%20Codezeile%20aus.%20Sollte%20hasname1%201%20oder%200%20zuweisen.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin%3A%200.0px%200.0px%200.0px%200.0px%3B%22%3Ehasname1%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%20Enth%C3%A4lt%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%20Spaltennamen%20erhalten%3CSTRONG%3E%20(%3C%2FSTRONG%3E%20Schnur%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%22name1%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.