Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Level VII

## How do I match the data of the first "ID"?

I tried to match the data of the last "ID" by pressing JSL below. How can I change it to match the data of the first "ID"?

``````dt = Open( "\$SAMPLE_DATA\Pizza Combined No Choice.jmp" );"
d2 = Open("\$SAMPLE_DATA\Pizza Profiles.jmp");
dt<<Update(With(d2),Match Columns(:Crust=:Crust),Add Columns from Update table( :ID));Wait(0);``````

Achieve the effect shown below,Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User

## Re: How do I match the data of the first "ID"?

Hi @lwx228

please have a look at the following solution. it my not be very robust but in this case it may do the trick.

``````dt = Open( "\$SAMPLE_DATA\Pizza Combined No Choice.jmp" );
d2 = Open( "\$SAMPLE_DATA\Pizza Profiles.jmp" );
d2 << New Column( "Crustindex",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( If( :Crust != Lag( :Crust, 1 ) | Row() == 1, 1, Lag( :Crustindex, 1 ) + 1 ) )
);
d2:Crustindex << delete formula;
d2 << Sort( By( :Crust, :Crustindex ), Order( Ascending, Descending ), replace table );Wait( 0 );
dt << Update( With( d2 ), Match Columns( :Crust = :Crust ), Add Columns from Update table( :ID ) );

``````

please let us know if it helps.

Ron

3 REPLIES 3
Highlighted
Super User

## Re: How do I match the data of the first "ID"?

Hi @lwx228

please have a look at the following solution. it my not be very robust but in this case it may do the trick.

``````dt = Open( "\$SAMPLE_DATA\Pizza Combined No Choice.jmp" );
d2 = Open( "\$SAMPLE_DATA\Pizza Profiles.jmp" );
d2 << New Column( "Crustindex",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( If( :Crust != Lag( :Crust, 1 ) | Row() == 1, 1, Lag( :Crustindex, 1 ) + 1 ) )
);
d2:Crustindex << delete formula;
d2 << Sort( By( :Crust, :Crustindex ), Order( Ascending, Descending ), replace table );Wait( 0 );
dt << Update( With( d2 ), Match Columns( :Crust = :Crust ), Add Columns from Update table( :ID ) );

``````

please let us know if it helps.

Ron

Highlighted
Level VII

## Re: How do I match the data of the first "ID"?

I see, there is no ready-made method, only through d2 reflexive sorting, and then use the matching method.

Thank you!
Highlighted
Super User

## Re: How do I match the data of the first "ID"?

Personally, if I had big and messy data, I would filter out the rows I do not want from d2 altogether. Only then I would know I have the update I want.

Article Labels

There are no labels assigned to this post.