cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
%3CLINGO-SUB%20id%3D%22lingo-sub-5088%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E3%82%B0%E3%83%A9%E3%83%95%E5%8C%96%E3%81%99%E3%82%8B%E5%89%8D%E3%81%AB%E5%88%97%E5%90%8D%E3%81%8C%E5%AD%98%E5%9C%A8%E3%81%99%E3%82%8B%E3%81%93%E3%81%A8%E3%82%92%E6%A4%9C%E8%A8%BC%E3%81%99%E3%82%8B%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%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E3%80%81%E3%82%B0%E3%83%A9%E3%83%95%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E5%89%8D%E3%81%AB%E3%80%81%E3%83%87%E3%83%BC%E3%82%BF%20%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%81%AB%E7%89%B9%E5%AE%9A%E3%81%AE%E5%88%97%E5%90%8D%E3%81%8C%E5%90%AB%E3%81%BE%E3%82%8C%E3%81%A6%E3%81%84%E3%82%8B%E3%81%93%E3%81%A8%E3%82%92%E6%A4%9C%E8%A8%BC%E3%81%97%E3%82%88%E3%81%86%E3%81%A8%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%3CSTRONG%3Ehasname1%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%20%E5%88%97%E5%90%8D%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%E3%82%B0%E3%83%A9%E3%83%95%E3%82%92%E4%BD%9C%E6%88%90%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E)%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E3%81%9F%E3%81%A0%E3%81%97%E3%80%81%E3%80%8Cname1%E3%80%8D%E3%81%AF%E6%96%87%E5%AD%97%E5%88%97%E3%83%87%E3%83%BC%E3%82%BF%E5%9E%8B%E3%81%A7%E3%81%82%E3%82%8A%E3%80%81%E5%88%97%E5%90%8D%E3%81%8C%E8%BF%94%E3%81%95%E3%82%8C%E3%82%8B%E3%81%9F%E3%82%81%E3%80%81%E6%AF%94%E8%BC%83%E3%81%AF%E6%B1%BA%E3%81%97%E3%81%A6%20true%20%E3%82%92%E8%BF%94%E3%81%97%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%3CSTRONG%3E%E5%88%97%E5%90%8D(colval)%3C%2FSTRONG%3E%E4%BB%96%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E5%9E%8B%E3%81%A7%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%E6%9C%89%E5%8A%B9%E3%81%AA%E6%96%87%E5%AD%97%E5%88%97%E6%AF%94%E8%BC%83%E3%82%92%E8%A1%8C%E3%81%86%E3%81%9F%E3%82%81%E3%81%AB%E5%88%97%E5%90%8D%E3%81%8B%E3%82%89%E6%96%87%E5%AD%97%E5%88%97%E5%80%A4%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%EF%BC%81%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%20%E3%82%B0%E3%83%A9%E3%83%95%E5%8C%96%E3%81%99%E3%82%8B%E5%89%8D%E3%81%AB%E5%88%97%E5%90%8D%E3%81%8C%E5%AD%98%E5%9C%A8%E3%81%99%E3%82%8B%E3%81%93%E3%81%A8%E3%82%92%E6%A4%9C%E8%A8%BC%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E3%81%86%E3%81%BE%E3%81%8F%E3%81%84%E3%81%8D%E3%80%81%E7%B4%A0%E6%99%B4%E3%82%89%E3%81%97%E3%81%8F%E3%80%81%E7%A7%81%E3%81%8C%E3%81%97%E3%81%A6%E3%81%84%E3%81%9F%E3%81%93%E3%81%A8%E3%82%88%E3%82%8A%E3%82%82%E3%81%AF%E3%82%8B%E3%81%8B%E3%81%AB%E7%9F%AD%E3%81%84.%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86%E3%81%94%E3%81%96%E3%81%84%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%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%20%E3%82%B0%E3%83%A9%E3%83%95%E5%8C%96%E3%81%99%E3%82%8B%E5%89%8D%E3%81%AB%E5%88%97%E5%90%8D%E3%81%8C%E5%AD%98%E5%9C%A8%E3%81%99%E3%82%8B%E3%81%93%E3%81%A8%E3%82%92%E6%A4%9C%E8%A8%BC%E3%81%99%E3%82%8B%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3Edt%20%26lt%3B%26lt%3B%20get%20column%20names(string)%3B%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%99%E3%80%82%E5%88%97%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8F%E6%96%87%E5%AD%97%E5%88%97%E3%81%A8%E3%81%97%E3%81%A6%E5%88%97%E5%90%8D%E3%82%92%E5%8F%96%E5%BE%97%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E3%81%93%E3%81%AE%201%20%E8%A1%8C%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84%E3%80%82%20hasname1%20%E3%81%AB%201%20%E3%81%BE%E3%81%9F%E3%81%AF%200%20%E3%82%92%E5%89%B2%E3%82%8A%E5%BD%93%E3%81%A6%E3%82%8B%E5%BF%85%E8%A6%81%E3%81%8C%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%80%82%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%E5%90%AB%E3%82%80%3C%2FSPAN%3E%3CSTRONG%3E(%3C%2FSTRONG%3E%20dt%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%26lt%3B%26lt%3B%3C%2FSPAN%3E%E5%88%97%E5%90%8D%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%3CSTRONG%3E(%3C%2FSTRONG%3E%E3%82%B9%E3%83%88%E3%83%AA%E3%83%B3%E3%82%B0%3CSTRONG%3E)%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%E3%80%81%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23a40095%3B%22%3E%20%E3%80%8C%E5%90%8D%E5%89%8D1%E3%80%8D%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.