Extracting String

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Beware that there may be other X characters in the key. In that case a different formulation will be required, such as

Code: Select all

If Right(InLink.TheString) = "X" Then Left(InLink.TheString,Len(InLink.TheString)-1) Else InLink.TheString
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

X is also removed if it is part of some other string, which i do not want..
Pradeep Kumar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok... if you are now saying that you only want to remove the 'X' from the field if it is the last character of the string, then you are right - you can't use a simple Convert function to do that.

You'll need to do something like Ray posted, check the last character and if it is an 'X' then extract everything up to (but not including) the last character, otherwise pass the entire field. Or count the number of 'X' characters and use EReplace to remove just the 'last' occurance. Whatever is appropriate.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thanks for the solution. Actually I am faced with a new problem now

My data has changed in flat file and is like:
23231A
236376A
738273A
63721A
ANGELIA
CHAMELIA
773626A

OUTPUT:
23231
236376
738273
63721
ANGELIA (HERE A SHOULD NOT BE REMOVED)
CHAMELIA (HERE A SHOULD NOT BE REMOVED)
773626

This is somewhat seems tough to me.. Any suggestions plz?
Pradeep Kumar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use Matches operator rather than equals operator.

Code: Select all

If InLink.TheString Matches "0X1N0X'A'" Then Left(InLink.TheString,Len(InLink.TheString)-1) Else InLink.TheString
or

Code: Select all

If Right(InLink.TheString) = "A" And Not(InLink.TheString Matches "1A0A") Then Left(InLink.TheString,Len(InLink.TheString)-1) Else InLink.TheString
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

This is insane. This is like giving you a timestamp 04/05/06 and tell you to determine if its MM/DD/YY or DD/MM/YY. Next to impossible.
If you can assure that the 'A' only shows up at the end of numeric values then you can use DIGITS() transform and get done with it by testing the first value and doing a ISNUM check on it.
Some generic rules need to be layed out.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Its not that A appears only at the end of numeric values. It also appears in others like
procter&gamble-G&A

I do not want A to be removed here.
Pradeep Kumar
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Ok i am glad there is a rule defined. Go for Ray's solution. See if it passes out all your tests. It should, Ray's solutions are pretty much all inclusive.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Well then work out a match pattern that will work for you. My first option would handle PROCTOR & GAMBLE - G&A properly, as there's no numeric character (to match the "1N" part of the pattern). Adapt.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thanks Ray.
Can you be little bit more clear Ray..
Pradeep Kumar
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

What is this Premium Contest
Pradeep Kumar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Here is a link which explains how you can enter the contest.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

I got it..How to see the full links of the solutions
Pradeep Kumar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sign up. It's less than $1 per week for the last lucky few (see home page).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply