BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Marwa_Se
Obsidian | Level 7

 

Hello!

 

I spent the whole day looking for solution for my problem but with no issue Woman Sad

 

I have a set of data which contains operations bank, i would like to extract only the name of the compagny or the business service

 

it's very complicated because the operation name is  a reference with lot of numbers and characters

 

For example:

 

operations

 

0123456789 2547 IKEA

5874521 265935 ORANGE ASSUR 254 147

77745812 MERCEDES 25477

257CARREFOUR15 1254 774

 

i would like to obtain a colum like this bellow:

 

Result

IKEA

ORANGE ASSUR

MERCEDES

CARREFOUR

 

Seriously the person who will find the solution for this would be a real Genius !!

 

Thank you in advance guys !! Woman Happy

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

That is weird. If I add CARD Bank, it works fine:

 

data have;
input var $char80.;
datalines;
0123456789 2547 IKEA
5874521 265935 ORANGE ASSUR 254 147
77745812 MERCEDES 25477
257CARREFOUR15 1254 774
CARD BANK 000170999200
;
run;
data want; set have;
length want $30;
want = prxchange('s/([\d|\s]*)(\D*)([\d|\s]*)/$2/',-1,var);
put want;
run;

 

IKEA
ORANGE ASSUR
MERCEDES
CARREFOUR
CARD BANK

 

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

data have;
input var $50.;
cards;
0123456789 2547 IKEA
5874521 265935 ORANGE ASSUR 254 147
77745812 MERCEDES 25477
257CARREFOUR15 1254 774
;

data want;
set have;
want=strip(compress(var,' ','kai'));
run;
ErikLund_Jensen
Rhodochrosite | Level 12

Hi

 

The easy way is to use prxchange to divide the string in tree elements, digits and blanks before first char, all chars and blanks up to first digit after, and the remaining digits/blanks, and drop

data have;
	input var $char80.;
datalines;
0123456789 2547 IKEA
5874521 265935 ORANGE ASSUR 254 147
77745812 MERCEDES 25477
257CARREFOUR15 1254 774
;
run;
data want; set have; 
	length want $30;
	want = prxchange('s/([\d|\s]*)(\D*)([\d|\s]*)/$2/',-1,var);
	put want;
run;

IKEA
ORANGE ASSUR
MERCEDES
CARREFOUR

the first and third element. The supplied code works with your data, but there might be combinations it cannot handle..

 

 

Marwa_Se
Obsidian | Level 7

Thank u a lo, it works but not for the whole references ,

 

I thought that was related to the length because i can't obtain the whole name

for example

 

for this reference :

 

CARD BANK 000170999200

 

i obtained ony : CARD

 

i added format var $100.;

 

but it doesn't work Woman Frustrated

 

 

ErikLund_Jensen
Rhodochrosite | Level 12

That is weird. If I add CARD Bank, it works fine:

 

data have;
input var $char80.;
datalines;
0123456789 2547 IKEA
5874521 265935 ORANGE ASSUR 254 147
77745812 MERCEDES 25477
257CARREFOUR15 1254 774
CARD BANK 000170999200
;
run;
data want; set have;
length want $30;
want = prxchange('s/([\d|\s]*)(\D*)([\d|\s]*)/$2/',-1,var);
put want;
run;

 

IKEA
ORANGE ASSUR
MERCEDES
CARREFOUR
CARD BANK

 

Marwa_Se
Obsidian | Level 7

thank u so much, but it's very strange even your method doesn't work for some references

 

i must have a problem with my database, i will focus ...

 

Thank you again for your help Woman Happy

ballardw
Super User

@Marwa_Se wrote:

thank u so much, but it's very strange even your method doesn't work for some references

 

i must have a problem with my database, i will focus ...

 

Thank you again for your help Woman Happy


Realizing that the example data you provided may not exactly match your real data you might provide as much of an example from your "real" data that has problems.

 

Some issues might be from encoding or possibly characters from the extended alphabet.

Marwa_Se
Obsidian | Level 7

Yes i adapted my database to the method and now it works perfectly Woman Happy

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 963 views
  • 6 likes
  • 4 in conversation