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

How to replace empty rows in select columns?

Hello JMP Community,

 

I have a data table that columns have specific name, first i wrote the script to select those columns, and i want to replace those column's empty rows with "REF", but other columns without those specific name won't change, how can i do this with JSL? Thanks.

 

 

SING_2-1656558042688.png

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Georg
Level VII

Re: How to replace empty rows in select columns?

Hi Sing,

I think there are two issues in your Script,

1st: your if referenced the wrong list (Col_List)

2nd: the action is not inside your if statement, but after, so the if cannot control the action.

Try the attached script, it should do the job. In addition to Jim's script I added the modifications you may need.

Names Default To Here( 1 );

dt = New Table( "test",
	New Column( "A::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "B::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "C::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "D::Test", "Character", set values( {"", "Test", ""} ) ),
	New Column( "value", set values( {1, 2, 3} ) )
);

colNameList = dt << get column names( string, character );

For( i = 1, i <= N Items( colNameList ), i++,
	Try(
		If( Contains( colNameList[i], "::LotData" ),
			As Column( dt, colNameList[i] )[dt << get rows where( As Column( dt, colNameList[i] ) == "" )] = "REF"
		), 

	)
);
Georg

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How to replace empty rows in select columns?

Here is a little script that loops through all of the character columns and then in each column, finds all of the rows that have empty cells, and sets them to REF

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

// Get the column names for all character columns
colNameList = dt << get column names( string, character );

For( i = 1, i <= N Items( colNameList ), i++,
	Try(
		As Column( dt, colNameList[i] )[dt << get rows where( As Column( dt, colNameList[i] ) == "" )] =
		"REF"
	)
);
Jim
SING
Level II

Re: How to replace empty rows in select columns?

Hi txnelson,

I tried the script you gave, but this will also replace value column, so can i only replace column with lot data?

I wrote this script but don't understand what's part be wrong.

 

 

dt = Current Data Table();
colNameList = dt << get column names( string, character );

For( i = 1, i <= N Items( colNameList ), i++,
	Try(
		If(Contains(Col_List[i], "::LotData")),
		As Column( dt, colNameList[i] )[dt << get rows where( As Column( dt, colNameList[i] ) == "" )] =
		"REF"
	)
);

 

 

 

 

Georg
Level VII

Re: How to replace empty rows in select columns?

Hi Sing,

I think there are two issues in your Script,

1st: your if referenced the wrong list (Col_List)

2nd: the action is not inside your if statement, but after, so the if cannot control the action.

Try the attached script, it should do the job. In addition to Jim's script I added the modifications you may need.

Names Default To Here( 1 );

dt = New Table( "test",
	New Column( "A::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "B::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "C::LotData", "Character", set values( {"", "YES", ""} ) ),
	New Column( "D::Test", "Character", set values( {"", "Test", ""} ) ),
	New Column( "value", set values( {1, 2, 3} ) )
);

colNameList = dt << get column names( string, character );

For( i = 1, i <= N Items( colNameList ), i++,
	Try(
		If( Contains( colNameList[i], "::LotData" ),
			As Column( dt, colNameList[i] )[dt << get rows where( As Column( dt, colNameList[i] ) == "" )] = "REF"
		), 

	)
);
Georg
SING
Level II

Re: How to replace empty rows in select columns?

Thanks a lot!
Thierry_S
Super User

Re: How to replace empty rows in select columns?

Hi,

Another non-scripting solution is to select your three columns, right-click on the headers > Standardize Attributes > Recode > replace the blanks with "REF."

CAUTION: Recoding cannot be undone, so make sure to save your table before going through the steps above.

Best,

TS

Thierry R. Sornasse