cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
miguello
Level VII

Associative Array from variables

Can somebody help me with a correct syntax  to create Associative Array from variables?

Now I have this:

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};

AB = [
	"AA" => a,
	"BB" => b
];

AB["AA"];

It returns:

 

/*:

a

I want it to return:

/*:

{"a1", "a2", "a3"}

I tried different combinations of Eval List(), Eval Expr(), Expr() and Eval(), but no luck.

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Associative Array from variables

You almost had it!  You need to input the arguments to Associative Array() as Associative Array( keys, values ), instead of Associative Array( {keys, values} ),

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array(keys, values);

AB["AA"];
Jordan

View solution in original post

4 REPLIES 4
Jasean
Staff

Re: Associative Array from variables

AB = Associative Array(EvalList({a, b}))
miguello
Level VII

Re: Associative Array from variables

This does not produce the desired result. Keep in mind, keys are "AA" and "BB", and values for those keys are lists a and b, respectively.

But it got me on the correct track, so this works as intended:

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array({keys, values});

AB["AA"];

Thanks!

 

P.S. Actually it doesn't work either.

 

I can't understand how JMP decides which one to use if my values are lists too??

//Create an associative array from a list that contains two lists of a key-value pair:

map = Associative Array( {{"yes", 0}, {"no", 1}} );

//Create an associative array from a list of keys and a list of values:

map = Associative Array( {"yes", "no"}, {0, 1} );

 

miguello
Level VII

Re: Associative Array from variables

Had to go brute force way for now:

 

AB = Associative Array();
AB["AA"] = Eval List(a);
AB["BB"] = Eval List(b);
ErraticAttack
Level VI

Re: Associative Array from variables

You almost had it!  You need to input the arguments to Associative Array() as Associative Array( keys, values ), instead of Associative Array( {keys, values} ),

 

a = {"a1", "a2", "a3"};
b = {"b1", "b2", "b3"};


keys = {"AA", "BB"};
values = Eval List({a, b});


AB = Associative Array(keys, values);

AB["AA"];
Jordan

Recommended Articles