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

Removing a part of the same string name for each row in different data tables

Hello all,

 

I have different data tables that i created from another tables, In each Data Tables, it contains strings of variable length in the format Character in the same column name. I've added some examples below. I am trying to remove the last 4 characters of the string from the column, and keep everything else. The last 4 characters are always "DATA", . I have tried to accomplish if statement to link different Data tables and using Left(), and Contains() but I think the way i wrote it is wrong. I hope I could get anyone help in this community since I just started to learn jmp jsl.

 

Ex:

Data Table 1

Source

FARAH_DATA

FARAH_DATA

FARAH_DATA

FARAH_DATA

 

Data Table 2

Source

MIKE_DATA

MIKE_DATA

MIKE_DATA

 

This is what I want the each Data Table looks like;

 

Data Table 1

Source

FARAH

FARAH

FARAH

FARAH

 

Data Table 2

Source

MIKE

MIKE

MIKE

 

I have attached my jsl as below

dtList = {};

For( i = 1, i <= N Table(), i++,
	tempdt = data table(i)<<get name;
	if(contains(eval(tempdt),"Subset"),
	insert into(dtList, tempdt ), // to define how many Data table created
	);
);

Current Data Table( dtList );

For( i = 1, i <= N Items( dtList ), i++, 
      dtList: Source [i] = Left( Source, Contains( Source, "DATA") - 2 );

1 REPLY 1
jthi
Super User

Re: Removing a part of the same string name for each row in different data tables

Many ways to handle this. Some examples how to delete _DATA from string

 

Names Default To Here(1);

str = "FARAH_DATA"; //Word Show(Word(1, str, "_")); //Contains and left/substr Show(Substr(str, 1, Contains(str, "_", -1) - 1)); Show(Left(str, Contains(str, "_", -1) - 1)); //Substitute Show(Substitute(str, "_DATA", "")); //Regex Show(Regex(str, "_DATA", "", GLOBALREPLACE)); Show(Regex(str, "^(.*?)(_DATA)", "\1"));

Using with datatables:

Names Default To Here(1)
dt1 = New Table("Untitled",
	Add Rows(4),
	New Column("Source",
		Character,
		"Nominal",
		Set Values({"FARAH_DATA", "FARAH_DATA", "FARAH_DATA", "FARAH_DATA"})
	)
);
dt2 = New Table("Untitled 2",
	Add Rows(3),
	New Column("Source",
		Character,
		"Nominal",
		Set Values({"MIKE_DATA", "MIKE_DATA", "MIKE_DATA"})
	)
);
dt_list = {dt1, dt2};
//using contains with left
//JMP16, if previous use For-loop
For Each({cur_dt}, dt_list,
	Column(cur_dt, "Source") << Set Each Value(Left(:Source, Contains(:Source, "_", -1) - 1));	
);

 

-Jarmo