cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
robust1972
Level IV

how to creat new column if same name column does not exist

hi,

I need to use few columns to do calculation. the  question I have is how to create new column and set value of each cell to 0 if same name column does not exist, it there is the column, do nothing. I tried below but it does not work the column already exist. can someone helps me out?


=Data Table( "FinalBiningTable" ) << Get Column Names();

(Column_list);

((contains(Column_list, "N(P, F)"))==0, Data Table( "FinalBiningTable" ) << New Column( "N(P, F)",numeric, ordinal );:Name("N(P, F)") << Set Each Value(0);, empty());

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: how to creat new column if same name column does not exist

//dt = data table("FinalBiningTable");  // Uncomment for your table

dt = open( "$sample_data\Big Class.jmp" );

column_list = dt << Get Column Names(string);

if (!contains(Column_list, "N(P, F)"),

      dt << New Column( "N(P, F)",numeric, ordinal, << Set Each Value(0));

);

View solution in original post

3 REPLIES 3
pmroz
Super User

Re: how to creat new column if same name column does not exist

//dt = data table("FinalBiningTable");  // Uncomment for your table

dt = open( "$sample_data\Big Class.jmp" );

column_list = dt << Get Column Names(string);

if (!contains(Column_list, "N(P, F)"),

      dt << New Column( "N(P, F)",numeric, ordinal, << Set Each Value(0));

);

robust1972
Level IV

Re: how to creat new column if same name column does not exist

Thanks! PMroz

What is wrong in my lines of code?

pmroz
Super User

Re: how to creat new column if same name column does not exist

The default data type for get column names is a list of columns (of column data type).  When you add the string argument you get a list of column names as strings.  You were trying to compare a column data type to a string.