Subscribe Bookmark RSS Feed

Create Unique Names for Unknown Number of Objects

robot

Community Trekker

Joined:

Feb 27, 2012

Hi,

I have a loop for unique row values where I create a subset and a graph for each loop.  How can I create and store unique object names for the each subset and graph created?  Thanks for your help.  I am using JMP11.

// Example.

Names Default To Here( 1 );

dt = Open( Convert File Path( "$Sample_Data" ) || "Big Class.jmp" );

ages = Associative Array( :age );

currentkey = ages << First;

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

  nextkey = ages << Next( currentkey );

  dt << Select Where( :age == currentkey );

  sub = dt << Subset( Output Table Name( "Subset " || Char( currentkey ) ) );

  // How can I create and store a unique object name for sub?

  dt << Clear Select;

  biv = sub << Bivariate( Y( :height ), X( :weight ) );

  // How can I create and store a unique object name for biv?

  currentkey = nextkey;

);

Close( dt, No Save );

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Instead of creating a new variable name for each subset table and bivariate report, try adding them to the associative array you already have:

// Example.

Names Default To Here( 1 );

dt = Open( Convert File Path( "$Sample_Data" ) || "Big Class.jmp" );

ages = Associative Array( :age );

currentkey = ages << First;

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

  nextkey = ages << Next( currentkey );

  ages[currentkey] = {}; // make each age hold a list

  dt << Select Where( :age == currentkey );

  // add the subset table to the list for this age:

  Insert Into(ages[currentkey], dt << Subset( Output Table Name( "Subset " || Char( currentkey ) ) ) );

  dt << Clear Select;

  // add the bivariate report to the list for this age:

  Insert Into(ages[currentkey], ages[currentkey][1] << Bivariate( Y( :height ), X( :weight ) ) );

  currentkey = nextkey;

);

Close( dt, No Save );

When you're done, the associative array looks like this:

Associative Array(

  {{12, {Data Table( "Subset 12" ), Bivariate[]}},

  {13, {Data Table( "Subset 13" ), Bivariate[]}},

  {14, {Data Table( "Subset 14" ), Bivariate[]}},

  {15, {Data Table( "Subset 15" ), Bivariate[]}},

  {16, {Data Table( "Subset 16" ), Bivariate[]}},

  {17, {Data Table( "Subset 17" ), Bivariate[]}}},

  0

)

You can access the subset table for any given age like this: ages[12][1]

You can access the bivariate report for any given age like this: ages[12][2]

3 REPLIES
vince_faller

Super User

Joined:

Mar 17, 2015

Is using the By function not an option?  Then you can just subset your biv.

Names Default To Here( 1 );

dt = Open( Convert File Path( "$Sample_Data" ) || "Big Class.jmp" );

biv = dt << Bivariate( Y( :height ), X( :weight ), by(:Age) );

biv[1]; //where age == 12

Solution

Instead of creating a new variable name for each subset table and bivariate report, try adding them to the associative array you already have:

// Example.

Names Default To Here( 1 );

dt = Open( Convert File Path( "$Sample_Data" ) || "Big Class.jmp" );

ages = Associative Array( :age );

currentkey = ages << First;

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

  nextkey = ages << Next( currentkey );

  ages[currentkey] = {}; // make each age hold a list

  dt << Select Where( :age == currentkey );

  // add the subset table to the list for this age:

  Insert Into(ages[currentkey], dt << Subset( Output Table Name( "Subset " || Char( currentkey ) ) ) );

  dt << Clear Select;

  // add the bivariate report to the list for this age:

  Insert Into(ages[currentkey], ages[currentkey][1] << Bivariate( Y( :height ), X( :weight ) ) );

  currentkey = nextkey;

);

Close( dt, No Save );

When you're done, the associative array looks like this:

Associative Array(

  {{12, {Data Table( "Subset 12" ), Bivariate[]}},

  {13, {Data Table( "Subset 13" ), Bivariate[]}},

  {14, {Data Table( "Subset 14" ), Bivariate[]}},

  {15, {Data Table( "Subset 15" ), Bivariate[]}},

  {16, {Data Table( "Subset 16" ), Bivariate[]}},

  {17, {Data Table( "Subset 17" ), Bivariate[]}}},

  0

)

You can access the subset table for any given age like this: ages[12][1]

You can access the bivariate report for any given age like this: ages[12][2]

robot

Community Trekker

Joined:

Feb 27, 2012

Excellent.  Thanks Melanie.  I did not realize an associative array can store objects like that.

Rob