cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.
  • See how to access JMP Marketplace - and - find, create & share add-ins to extend your JMP. Watch video.

Discussions

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

Create Associative Array from Column Values

I would like to create an associative array from column values.  I am curious if anyone in the JMP community has a clever solution.  I am using JMP10.  An example is below.

// For the following data table:

example = New Table( "Example Data", Add Rows( 27 ),  New Column( "Lot", Character, Nominal, Set Values(

{"A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "C", "C"}

) ),  New Column( "Test", Character, Nominal, Set Values(

{"Test1", "Test1", "Test1", "Test2", "Test2", "Test2", "Test3", "Test3", "Test3", "Test1", "Test1", "Test1", "Test2", "Test2", "Test2",

"Test3", "Test3", "Test3", "Test1", "Test1", "Test1", "Test2", "Test2", "Test2", "Test3", "Test3", "Test3"}

) ),  New Column( "Parameter", Character, Nominal, Set Values(

{"Param1", "Param2", "Param3", "Param1", "Param2", "Param3", "Param1", "Param2", "Param3", "Param1", "Param2", "Param3", "Param1",

"Param2", "Param3", "Param1", "Param2", "Param3", "Param1", "Param2", "Param3", "Param1", "Param2", "Param3", "Param1", "Param2",

"Param3"} ) ),  New Column( "Yield", Numeric, Continuous, Format( "", 16 ),

Set Values( [1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0] )

),  New Column( "Defect Code", Character, Nominal, Formula( If( :Yield == 0, :Test || "_" || :Parameter ) ) ) );

// I would like to create an associative array with key = Lot, and values = Defect Codes.  Please see example below.

// What is the best way to script this?

// As a bonus, is it possible to create an associative array with multiple levels (IE: Lot => Test => Parameter => Defect Code)?

Defects = Associative Array( example:Lot );

Defects["A"] = {"Test1_Param3", "Test2_Param2", "Test2_Param3", "Test3_Param2"};

Defects["B"] = {"Test1_Param1", "Test1_Param2", "Test1_Param3", "Test2_Param2", "Test3_Param2", "Test3_Param3"};

Defects["C"] = {"Test1_Param2", "Test1_Param3", "Test2_Param3", "Test3_Param3"};

// Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
robot
Level VI

Re: Create Associative Array from Column Values

If anyone is curious:

Defects = Associative Array( :Lot );

currentkey1 = Defects << First;

For( i = 1, i <= N Items( Defects ), i++,

  values1 = Associative Array( :Test[example << Get Rows Where( :Lot == currentkey1 )] );

  Defects[currentkey1] = values1;

  currentkey2 = Defects[currentkey1] << First;

  For( j = 1, j <= N Items( Defects[currentkey1] ), j++,

  values2 = :Defect Code[example << Get Rows Where( :Lot == currentkey1 & :Test == currentkey2 & :Yield == 0 )];

  Defects[currentkey1][currentkey2] = values2;

  nextkey2 = Defects[currentkey1] << Next( currentkey2 );

  currentkey2 = nextkey2;

  );

  nextkey1 = Defects << Next( currentkey1 );

  currentkey1 = nextkey1;

);

Show( Defects );

View solution in original post

2 REPLIES 2
robot
Level VI

Re: Create Associative Array from Column Values

I figured out how to create an associative array with key = Lot, and values = Defect Codes.

I am curious if there is any advice about associative arrays with multiple levels.  Thanks!

Defects = Associative Array( example:Lot );

currentkey = Defects << First;

For( i = 1, i <= N Items( Defects ), i++,

  values = :Defect Code[example << Get Rows Where( :Lot == currentkey & :Yield == 0 )];

  Defects[currentkey] = values;

  nextkey = Defects << Next( currentkey );

  currentkey = nextkey;

);

Show( Defects );

robot
Level VI

Re: Create Associative Array from Column Values

If anyone is curious:

Defects = Associative Array( :Lot );

currentkey1 = Defects << First;

For( i = 1, i <= N Items( Defects ), i++,

  values1 = Associative Array( :Test[example << Get Rows Where( :Lot == currentkey1 )] );

  Defects[currentkey1] = values1;

  currentkey2 = Defects[currentkey1] << First;

  For( j = 1, j <= N Items( Defects[currentkey1] ), j++,

  values2 = :Defect Code[example << Get Rows Where( :Lot == currentkey1 & :Test == currentkey2 & :Yield == 0 )];

  Defects[currentkey1][currentkey2] = values2;

  nextkey2 = Defects[currentkey1] << Next( currentkey2 );

  currentkey2 = nextkey2;

  );

  nextkey1 = Defects << Next( currentkey1 );

  currentkey1 = nextkey1;

);

Show( Defects );

Recommended Articles