Column name from stringHi everyone,
I am working on a script that I would like to use a string as a column name, and use that column name in a formula, see below:
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt << New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );
//can we get another column to take 'a' as an input?
dt << New Column("Gort", formula(column(a)*:Y));When I use this however, it does not see "klaatu barada nikto" as a valid column, even though we created it before.
From other posts I have seen that the column() function can be used to assign a string to a column and I have used it in this way before, but in this instance it does not work. All we end up with is this:

Does anyone know a workaround for this? Thanks for any help in advance!
Advanced Statistical ModelingAutomation and ScriptingDesign of ExperimentsRe: Column name from stringIf I understand correctly what you want, you could try adding Name Expr
Names Default To Here(1);
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt << New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );
Eval(EvalExpr(dt << New Column("Gort", numeric, formula(Expr(Name Expr(As Column(a)))*:Y))));

Re: Column name from stringJarmo,
I'm using the same approach in one of my scripts and bumped into a problem: the formula in the new column will have that "a" column as this:
Formula(As Column("klaatu barada nikto")*:Y)which means that if name of that column changes (and in my case it changes) this formula will become invalid. I need to somehow reference it not as As Column("name") but as :name - any way to do that?
</CODE><CODE class=" language-jsl">
</CODE></P><P> </P><P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-393062" slang="en-US" mode="NONE">Re: Column name from string</LINGO-SUB><LINGO-BODY id="lingo-body-393062" slang="en-US" mode="NONE"><P>Fantastic! Thank you so much for your help.</P></LINGO-BODY><LINGO-SUB id="lingo-sub-393057" slang="en-US" mode="NONE">Re: Column name from string</LINGO-SUB><LINGO-BODY id="lingo-body-393057" slang="en-US" mode="NONE"><P>Take a look at this <A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank">Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute</A> </P><P> </P><PRE><CODE class=" language-jsl">dt = Open( "$SAMPLE_DATA/Cities.jmp" );
//example column
dt << New Column("klaatu barada nikto", formula(3));
//suppose we don't know what exactly will be in 'a' as it is controlled by a for loop etc.
a = Concat Items( {"klaatu", "barada", "nikto"}, " " );
//can we get another column to take 'a' as an input?
Eval(EvalExpr(dt << New Column("Gort", numeric, formula(ascolumn(expr(a))*:Y))));