Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: Create local variables that hold lists from column names

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 4, 2018 10:25 PM
(995 views)

Hi 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)<<Get Values)<<get keys));

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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));
```

4 REPLIES 4

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Create local variables that hold lists from column names

Not 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]);
);
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Create local variables that hold lists from column names

ian 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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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));
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Create local variables that hold lists from column names

ian thx. this is great, i was battling for 2 days to solve it, appreciate that :)