cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
%3CLINGO-SUB%20id%3D%22lingo-sub-5088%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9C%A8%E7%B9%AA%E5%9C%96%E4%B9%8B%E5%89%8D%E9%A9%97%E8%AD%89%E5%88%97%E5%90%8D%E7%A8%B1%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%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%E5%97%A8%EF%BC%8C%E6%88%91%E6%83%B3%E5%9C%A8%E5%89%B5%E5%BB%BA%E5%9C%96%E8%A1%A8%E4%B9%8B%E5%89%8D%E9%A9%97%E8%AD%89%E6%95%B8%E6%93%9A%E8%A1%A8%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%9F%90%E5%80%8B%E5%88%97%E5%90%8D%EF%BC%9A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%20hasname1%20%3D%200%3B%20%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20for%EF%BC%88colval%20%3D%3D%201%EF%BC%8Ccolval%20%26lt%3B%3D%20Ncols%EF%BC%88dt%EF%BC%89%EF%BC%8Ccolval%20%2B%2B%EF%BC%8C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20colName%20%3D%E5%88%97%E5%90%8D%EF%BC%88colval%EF%BC%89%3B%20%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20if%EF%BC%88colName%20%3D%3D%E2%80%9Cname1%E2%80%9D%EF%BC%8C%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%20hasname1%20%3D%201%3B%20%3C%2FSTRONG%3E%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BC%9F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E8%AC%9D%E8%AC%9D%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%EF%BC%9A%E5%9C%A8%E7%B9%AA%E5%9C%96%E4%B9%8B%E5%89%8D%E9%A9%97%E8%AD%89%E5%88%97%E5%90%8D%E7%A8%B1%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5090%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%B7%A5%E4%BD%9C%EF%BC%8C%E5%BE%88%E6%A3%92%EF%BC%8C%E6%AF%94%E6%88%91%E6%AD%A3%E5%9C%A8%E5%81%9A%E7%9A%84%E6%9B%B4%E7%9F%AD%E3%80%82%26nbsp%3B%20%E8%AC%9D%E8%AC%9D%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%EF%BC%9A%E5%9C%A8%E7%B9%AA%E5%9C%96%E4%B9%8B%E5%89%8D%E9%A9%97%E8%AD%89%E5%88%97%E5%90%8D%E7%A8%B1%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-5089%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%BD%A0%E5%8F%AF%E4%BB%A5%E4%BD%BF%E7%94%A8dt%20%26lt%3B%26lt%3B%20get%20column%20names%EF%BC%88string%EF%BC%89%3B%E5%B0%87%E5%88%97%E5%90%8D%E7%A8%B1%E4%BD%9C%E7%82%BA%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%80%8C%E4%B8%8D%E6%98%AF%E5%88%97%E5%B0%8D%E8%B1%A1%E3%80%82%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%E8%A9%A6%E8%A9%A6%E9%80%99%E4%B8%80%E8%A1%8C%E4%BB%A3%E7%A2%BC%E3%80%82%E6%87%89%E8%A9%B2%E7%82%BAhasname1%E5%88%86%E9%85%8D1%E6%88%960%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%20%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%3D%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%232400eb%3B%22%3E%E5%8C%85%E5%90%AB%3C%2FSPAN%3E%3CSTRONG%3E%20%EF%BC%88%20%3C%2FSTRONG%3E%20DT%20%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%26lt%3B%26lt%3B%20%3C%2FSPAN%3E%E7%8D%B2%E5%8F%96%E5%88%97%E5%90%8D%E7%A8%B1%3CSTRONG%3E%20%EF%BC%88%20%3C%2FSTRONG%3E%E4%B8%B2%3CSTRONG%3E%20%EF%BC%89%20%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%EF%BC%8C%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20%23a40095%3B%22%3E%20%E2%80%9CNAME1%E2%80%9D%20%3C%2FSPAN%3E%3CSTRONG%3E%20%EF%BC%89%20%3C%2FSTRONG%3E%3CSPAN%20style%3D%22color%3A%20%23130098%3B%22%3E%20%3B%20%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.