Create local variables that hold lists from column namesHi all,
Need your help with creating multiple local variables that contain column names within var name.
I'v tried this butget an err.
Any suggestions?
for(j=1,j<=ncol(dt),j++,
local(parse(char(column name(j))||"key")=Associative Array(column(j)<Re: Create local variables that hold lists from column namesian thx. this is great, i was battling for 2 days to solve it, appreciate that
Re: Create local variables that hold lists from column names
OK. Here's one way, and I'm sure there will be others:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
varList = {};
For( j = 1, j <= N Col( dt ), j++,
varName = (Column(dt, j ) << getName)||"_keys";
keys = Associative Array( Column(dt, j ) << Get Values ) << get keys;
makeVar = Expr(LHS = RHS);
SubstituteInto(makeVar, Expr(LHS), Parse(varName), Expr(RHS), Eval(keys));
makeVar;
InsertInto(varList, Parse(varName));
);
Print(varList);
Print(EvalList(varList));Re: Create local variables that hold lists from column namesian thx,
My intention is that for each list that was created by associative aray function it will also have a unique variable name that contain the matched column name.
For example: if I have two columns: Entity and Lot, then I will get two local variables :
Entitykey={entity1, entity2}
Lotkey={Lot1,Lot2}....
And so on for all columns in table
Re: Create local variables that hold lists from column namesNot sure I understand your use of 'Local()', but is this close to what you want?
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
keyVarList = {};
For( j = 1, j <= N Col( dt ), j++,
keys = Associative Array( Column( j ) << Get Values ) << get keys;
InsertInto(keyVarList, EvalList(List(keys)));
);
for(j = 1, j <= NItems(keyVarList), j++,
Print(keyVarList[j]);
);