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

How do I change all occurrences of xyz:# to xyz

I need a script to loop across all character columns and find those who have the pattern xyz:#, and convert to xyz.  I have a program that adds a numerical value to each duplicate sample I analyze, however, I recode each duplicate sample name to remove the assigned number as part of my data clean-up.  Can this process be scripted?  Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I change all occurrences of xyz:# to xyz

I think this will do what you want

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

colList = dt << get column names( character, string );
For( i = 1, i <= N Items( colList ), i++,
	For Each Row(
		as Column( dt, colList[i] ) = Try(
			Word( 1, As Column( dt, colList[i] ), ":" )
		,
			As Column( dt, colList[i] )
		)
	)
);

If you are going to be continuing with scripting, you need to take the time to read the Scripting Guide in the JMP Documentation Library, available under the Help pull down menu.

The Discussion Group is not here to write code for the users, it is here to help users with issue they are finding when using JMP or in writing scripts.  The community will always be here to assist JMP users with getting through the problems they run into.

Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How do I change all occurrences of xyz:# to xyz

When you state xyz:# is that literally the value or are you referring to xyz as being a character place holder like
abcd:#
zzqr:#
or are you referring to # as being a numeric place holder like
abcd:123
zzqr:874
Jim
KRT
KRT
Level II

Re: How do I change all occurrences of xyz:# to xyz

XYZ is a placeholder that is referring to what I named the sample.  So for example, I analyze a sample that I name "Texas Tea" in triplicate, the program will return the data with the names, "Texas Tea:1, Texas Tea:2, and Texas Tea:3".

txnelson
Super User

Re: How do I change all occurrences of xyz:# to xyz

I think this will do what you want

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

colList = dt << get column names( character, string );
For( i = 1, i <= N Items( colList ), i++,
	For Each Row(
		as Column( dt, colList[i] ) = Try(
			Word( 1, As Column( dt, colList[i] ), ":" )
		,
			As Column( dt, colList[i] )
		)
	)
);

If you are going to be continuing with scripting, you need to take the time to read the Scripting Guide in the JMP Documentation Library, available under the Help pull down menu.

The Discussion Group is not here to write code for the users, it is here to help users with issue they are finding when using JMP or in writing scripts.  The community will always be here to assist JMP users with getting through the problems they run into.

Jim