BookmarkSubscribeRSS Feed
buddha_d
Pyrite | Level 9

Hi SAS community,

             I have this scenario, where I need to extract account numbers from a string and it is messy and need help to fix it. 

eg:

data have;
input accountnumber $50.;
cards;
pcg1234500008765CheckingPCG000006878siim
OAK000000345697000000CHECK
MMTAYL8202206ERRA23124999GIG
YYY2356543ach78Y34????
;
run;

WANT
1234500008765CheckingPCG000006878
000000345697000000
8202206ERRA23124999
2356543ach78Y34

 

I tried to use anydigit and substring function to start the right number, but I can't finish how to substring to get to the last digit? 

 

Can someone help?

 

thanks 

 

4 REPLIES 4
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
The data you want still has letters in it--is there a systematic approach to the letters you are trying to keep? The COMPRESS() function has a handy 3rd argument for determining which kinds of characters to keep, but I'm not sure if it applies in this case.

https://documentation.sas.com/doc/en/pgmsascdc/v_031/fedsqlref/n01p24mgwawxa2n1hy4gwe5t59xf.htm
buddha_d
Pyrite | Level 9

I can't use the compress function as it eliminates even the letters in between account number. some account numbers are masked with letters for security reasons. So, this might not be an option.
Thanks for responding. 

ballardw
Super User

Rules for why in

pcg1234500008765CheckingPCG000006878siim

you remove the first pcg but keep the second PCG are going to complicate this a lot.

 

Do you have any documentation about the components of that obnoxious string from the source?

That you can share?

 

buddha_d
Pyrite | Level 9

Ballardw, 
         This is just dummy data that I created. The real production data is messy. I just observed some pattern and posted it. I do need to extract the starting numerical digit (along with any letters are there in between) and ending numerical digit. How could I get it? I could get the starting numerical value for all the values, but to get the entrire string till the last number digit is the real challenge. Could someone help me in that please? 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1260 views
  • 0 likes
  • 3 in conversation