cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Pacco
Level III

add rows after selected rows

Hello community,I am new to jmp and have troubles with creating a script that would add 1 row after each selected row within my dataset. Any ideas? My code looks like this so far:

 

dt=Current data Table ();
dt<<add rows(1,46030);

 

However, this of course adds a row only after the specified column. I selected my rows according to a sepcific name in one column and a sepcific value wihtin another column. How can I automatically enter a row after all my selected rows that are not adjacent but have unselected rows in between them?

 

Thanks in advance for your help!

 

 

I

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: add rows after selected rows

Because the inserted rows will change the selected row numbers, the below modification to @uday_guntupalli script has to be made to actually get the results you want.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dt << Select Randomly( 0.1 ); // Selecting rows randomly 

SR = dt << Get Selected Rows;  // Get list of selected rows 

For( i = 1, i <= N Rows( SR ), i++,
	dt << Add Rows( 1, SR[i] ); // Add 1 row after each selected row
	SR = dt << Get Selected Rows;
);
Jim

View solution in original post

txnelson
Super User

Re: add rows after selected rows

$SAMPLE_DATA

is an special environment variable for JMP.  The structure of the OPEN() function is:

     Open( file path, <invisible>, <private>, <select columns(list)> | <ignore columns(list)> )

See below, the Scripting Index for the Open

open.PNG

 

Jim

View solution in original post

6 REPLIES 6
uday_guntupalli
Level VIII

Re: add rows after selected rows

@Pacco
        Welcome to the JMP Community.  Let me try and explain this and solve the problem. The Add Rows messge only specifies the # of rows and where to add so JMP is executing what the function is telling it to do. In order to scale it for your needs , we can try the following : 

 

dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dt << Select Randomly(0.1); // Selecting rows randomly 

SR = dt << Get Selected Rows;  // Get list of selected rows 

for(i = 1 , i <= N Rows(SR), i++,
		dt << Add Rows(1,SR[i]); // Add 1 row after each selected row
   );

Hope this helps and addresses your question 

Best
Uday
txnelson
Super User

Re: add rows after selected rows

Because the inserted rows will change the selected row numbers, the below modification to @uday_guntupalli script has to be made to actually get the results you want.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Cities.jmp" );

dt << Select Randomly( 0.1 ); // Selecting rows randomly 

SR = dt << Get Selected Rows;  // Get list of selected rows 

For( i = 1, i <= N Rows( SR ), i++,
	dt << Add Rows( 1, SR[i] ); // Add 1 row after each selected row
	SR = dt << Get Selected Rows;
);
Jim
Pacco
Level III

Re: add rows after selected rows

Thanks a lot, this script work perfectly for me.

 

The only thing I don´t understand, yet, is why my 

dt<< open("$...");

function doesn´t work. I always have to use dt<< CurrentDataTable (); while having my table open already.

 

Thanks again for the valuable information!

txnelson
Super User

Re: add rows after selected rows

dt<< open("$...");

is incorrect.  The specified usage is

dt = Open(:$...");

It opens up the sample data table and assigns a handle to the openned data table called "dt";

dt = Current Data Table();

does the same thing as the Open() function, except it asigns to "dt" a pointer/handle to the current active data table.

See

     Help>Scripting Index

for further details.

Jim
Pacco
Level III

Re: add rows after selected rows

Thanks for th efast Reply, however, I tried out all variations with your answer and it still gives me this error:

Unexpected "$".
Trying to parse operand for ":" operator.
Line 1 Column 13: dt = Open (:►$SMHI_Trend_IKEU_Profiler_merge_only 2

I wrote several variations like this one:

dt = Open (:$SMHI_Trend_IKEU_Profiler_merge_only 20 year.jmp");

Any ideas, what I am doing wrong? (I am a very beginner in this, sorry)
txnelson
Super User

Re: add rows after selected rows

$SAMPLE_DATA

is an special environment variable for JMP.  The structure of the OPEN() function is:

     Open( file path, <invisible>, <private>, <select columns(list)> | <ignore columns(list)> )

See below, the Scripting Index for the Open

open.PNG

 

Jim