BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

The string in my data is like :

 

Message 

During bankAccount 'BSD0139' .

Error 'MATF081' csv.

Solvecy bank 'MATF026' line

Programme '22337' run

 

I would like to remove all the codes like BSD0139.

Do you know please the function for it ? When I'm doing translate(Message,'','0123456789'), I remove only the numeric values.

 

Thank you for your help !

 

SASdevAnneMarie_0-1652720879184.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.


The best way to provide data is via the following:

Data2DataStep Maco instructions will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

Having said that, and then making some assumptions about your data, you probably need to be looking at Regular Expressions

Here's an example that might do what you want:

data have ;
	infile cards ;
	input string $40. ;
cards ;
During bankAccount BSD0139 update.
During bankAccount MATF081 update.
During bankAccount MATF026 update
during bankAccount 22337 update
;
run ;

data want ;
	set have ;
	newString=prxchange('s/[A-Z]{3,4}[0-9]{3,4} //', -1, string);
	put string= @50 newString= ;
run ;

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Does the string ALWAYS begin with

During bankAccount 

or can there be other beginning strings?

 

Does the uppercase you want to remove ALWAYS begin in column 20? Or can it be other places in the string?

 

Please explain the logic by which a programmer could find this string in the larger text string.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Hello,

Sorry, I udated my question.
I would like to remove the code 'FFYY77', 'KKLM', the code is always in uppercase. The string is variable, but I have a one code in the string.
PaigeMiller
Diamond | Level 26

So when I ask for information

Please explain the logic by which a programmer could find this string in the larger text string.

I am expecting you to respond to this request, but I don't see one.

 

In addition, you have now changed the problem to where the string of interest is now in quotes (whereas before it was not in quotes). Is that how the data really appears, with quotes around the string you want to remove?? Or not?

--
Paige Miller
Tom
Super User Tom
Super User

Not sure what UPPERCASE has to do with your quesition.

If looks like you want to remove the word that follows the word "bankAccount".

 

Is that the actual problem you are trying to solve?

 

NOTE: The TRANSLATE() function converts individual characters.  Your code was just converting the digits into spaces.

SASdevAnneMarie
Barite | Level 11
Hello,
Sorry, I udated my question.
I would like to remove the code 'FFYY77', 'KKLM', the code is always in uppercase. The string is variable, but I have a one code in the string.
ballardw
Super User

@SASdevAnneMarie wrote:
Hello,
Sorry, I udated my question.
I would like to remove the code 'FFYY77', 'KKLM', the code is always in uppercase. The string is variable, but I have a one code in the string.

Show example data that matches your requirement and the desired result. At the time I read this your "data" has no values containing FFYY77 or KKLM

 

If it is only those values than perhaps TRANWRD. If it is based on position in a longer string then provide actual examples.

 

What I see in your first post is this:

The string in my data is like :

 

Message 

During bankAccount 'BSD0139' .

Error 'MATF081' csv.

Solvecy bank 'MATF026' line

Programme '22337' run

 

I would like to remove all the codes like BSD0139.

Do you know please the function for it ? When I'm doing translate(Message,'','0123456789'), I remove only the numeric values.

 

Thank you for your help !

 

ballardw_0-1652721970816.png

 

 

SASdevAnneMarie
Barite | Level 11
Thank you Ballardw,

I added the data.
AMSAS
SAS Super FREQ

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.


The best way to provide data is via the following:

Data2DataStep Maco instructions will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

Having said that, and then making some assumptions about your data, you probably need to be looking at Regular Expressions

Here's an example that might do what you want:

data have ;
	infile cards ;
	input string $40. ;
cards ;
During bankAccount BSD0139 update.
During bankAccount MATF081 update.
During bankAccount MATF026 update
during bankAccount 22337 update
;
run ;

data want ;
	set have ;
	newString=prxchange('s/[A-Z]{3,4}[0-9]{3,4} //', -1, string);
	put string= @50 newString= ;
run ;
SASdevAnneMarie
Barite | Level 11
Thank you, Amsas,

Could you please explain what means {3,4} in your code ?
Patrick
Opal | Level 21

Using Regular Expressions is one way to go about this. 

To define the appropriate Regular Expression one needs to fully understand the text pattern of your source data.

Based on the sample data you've posted in your Excel attachment below RegEx could work.

data have;
  infile datalines truncover;
  input message $80.;
datalines;
Error during bankAccount CCBP294 update
Error during bankAccount CCBP297 update
Error during bankAccount UBS0138 update
Error during creation of bankAccount BGPL590 for csv line 12311
Error during bankAccount BPLL009 update
Error during bankAccount BPMC001 update
Error during creation of bankAccount CICI002 for csv line 13289
Error during bankAccount BCA1240 update
Error during creation of bankAccount MILL007 for csv line 13427
Error during bankAccount KBL0386 update
Error during bankAccount UBS0417 update
Error during bankAccount WARG100 update
Error during bankAccount BGPJ435 update
Error during bankAccount BSD1587 update
Error during creation of bankAccount COPA137 for csv line 14607
Error during deactivation of company 290
Error during deactivation of company 291
Error during deactivation of company 292
Error during deactivation of company 293
Error during deactivation of company 294
;

data want;
  set have;
  if 0 then message_2=message;
  message_2=prxchange('s/^(.*?bankaccount) \b\w*\b(.*)$/$1 <removed>$2/oi',1,strip(message));
run;

proc print data=want;
run;

Patrick_0-1652782031336.png

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 680 views
  • 1 like
  • 6 in conversation