cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
dadawasozo
This widget could not be displayed.
" alt = "Level IV"/> dadawasozo
Level IV

get rows in between characters from a column then move other column value (selected row only) to other column

Hi,

 

I want to move or copy paste multiple column value of selected rows to other columns in the same table like picture below

the interested rows are always start from :Item == "start" until :Item == "values", but the total rows can be different. I want to copy paste or move value in Col1 and Col2 of the interested rows to Col 3 and Col 4. My current thought is to manually create a list that include the string from start to values under :Item then create a column to label as "1" if :Item contains list. from there set the Col 3 == Col 1 and Col 4 = Col 2. 

However, the rows between start and values can be different. I wonder if anyone know better method to do the task without the need of manually create the list, but based on the "start" and "values" to find the rows.
original table

dadawasozo_0-1744129588431.png

 after moved

dadawasozo_1-1744129629132.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
mmarchandFSLR
This widget could not be displayed.
" alt = "Level V"/> mmarchandFSLR
Level V

Re: get rows in between characters from a column then move other column value (selected row only) to other column

I think you can safely do it without a config table.  This checks to make sure that Col 1 contains a value in the "start" row before overwriting anything.  Yes, I like using For Each().

 

Names Default To Here( 1 );
starts = Loc( dt:Item << Get Values, "start" );
ends = Loc( dt:Item << Get Values, "values" );
For Each( {v, i}, starts,
	If( :Col 1[v] != "",
		For Each( {val, idx}, v :: ends[i],
			:Col 3[val] = :Col 1[val];
			:Col 4[val] = :Col 2[val];
			:Col 1[val] = "";
			:Col 2[val] = "";
		)
	)
);

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: get rows in between characters from a column then move other column value (selected row only) to other column

I suspect it would be easier to manually do the cut and paste rather than having to create start and stop lists.

Jim
dadawasozo
This widget could not be displayed.
" alt = "Level IV"/> dadawasozo
Level IV

Re: get rows in between characters from a column then move other column value (selected row only) to other column

but the purpose is for daily automation and the rows between the start and values can change from time to time.

txnelson
Super User

Re: get rows in between characters from a column then move other column value (selected row only) to other column

Then I would make it as straight forward as possible and create a config table something like

txnelson_0-1744132577546.png

Which makes your JSL pretty simple, something like:

Names Default To Here( 1 );
dt = Current Data Table();
dtConfig = Data Table( "Config" );

For( i = 1, i <= N Rows( dtConfig ), i++,
	frCol = dtConfig:From Column[i];
	toCol = dtConfig:To Column[i];
	For( k = dtConfig:Start Row[i], k <= dtConfig:End Row[i], k++,
		Column( dt:toCol )[k] = Column( dt, FromCol )[k];
		If( dtConfig:Move_Copy == "Move",
			Column( dt, FromCol ) = ""
		);
	);
);

 

Jim
mmarchandFSLR
This widget could not be displayed.
" alt = "Level V"/> mmarchandFSLR
Level V

Re: get rows in between characters from a column then move other column value (selected row only) to other column

I think you can safely do it without a config table.  This checks to make sure that Col 1 contains a value in the "start" row before overwriting anything.  Yes, I like using For Each().

 

Names Default To Here( 1 );
starts = Loc( dt:Item << Get Values, "start" );
ends = Loc( dt:Item << Get Values, "values" );
For Each( {v, i}, starts,
	If( :Col 1[v] != "",
		For Each( {val, idx}, v :: ends[i],
			:Col 3[val] = :Col 1[val];
			:Col 4[val] = :Col 2[val];
			:Col 1[val] = "";
			:Col 2[val] = "";
		)
	)
);

Recommended Articles