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%3EValidate%20column%20name%20exists%20before%20graphing%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%3EHi%2C%26nbsp%3B%20I%20am%20trying%20to%20validate%20that%20a%20data%20table%20contains%20a%20certain%20column%20name%20prior%20to%20creating%20graphs%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3Ehasname1%20%3D%200%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%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%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20colName%20%3D%20Column%20Name(colval)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(%20colName%20%3D%3D%20%22name1%22%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20hasname1%20%3D%201%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20)%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Eif%20(hasname1%20%3D%3D%201%2C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2Fcreate%20graph%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20)%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EHowever%2C%20the%20comparison%20never%20returns%20true%20because%20%22name1%22%20is%20a%20string%20data%20type%2C%20and%20the%20column%20name%20returned%20from%20%3CSTRONG%3EColumn%20Name(colval)%3C%2FSTRONG%3E%20is%20some%20other%20data%20type.%3C%2FP%3E%3CP%3EHow%20can%20I%20get%20a%20string%20value%20from%20a%20Column%20Name%20to%20make%20a%20valid%20string%20comparison%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThanks!%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%20Validate%20column%20name%20exists%20before%20graphing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EWorks%2C%20great%2C%20and%20much%20shorter%20than%20what%20I%20was%20doing.%26nbsp%3B%20Thank%20you.%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%20Validate%20column%20name%20exists%20before%20graphing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EYou%20can%20use%20dt%20%26lt%3B%26lt%3B%20get%20column%20names(string)%3B%20to%20get%20column%20names%20as%20a%20string%20instead%20of%20a%20column%20object.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ETry%20this%20single%20line%20of%20code.%20Should%20assign%201%20or%200%20to%20hasname1.%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%20style%3D%22margin%3A%200.0px%200.0px%200.0px%200.0px%3B%22%3Ehasname1%20%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22color%3A%20%232400eb%3B%22%3EContains%3C%2FSPAN%3E%3CSTRONG%3E(%3C%2FSTRONG%3E%20dt%20%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%26lt%3B%26lt%3B%3C%2FSPAN%3E%20get%20column%20names%3CSTRONG%3E(%3C%2FSTRONG%3E%20string%20%3CSTRONG%3E)%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22color%3A%20%23a40095%3B%22%3E%22name1%22%3C%2FSPAN%3E%20%3CSTRONG%3E)%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%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.