BookmarkSubscribeRSS Feed
Alexxxxxxx
Pyrite | Level 9

Hello,

 

In a  company name standardisation process, I expect to 'Convert “AND”, “ET”, “Y”, “UND” and so on, to “&”.  and Remove all other punctuation.'

 

So, I would like to do it by following steps,

1. split a variable into several independent variables.

2. Convert “AND”, “ET”, “Y”, “UND” and so on, to “&”.

3. Remove all other punctuation.

4. merge them together ( both keep the original variable and new variable).

5. create a new variable to remind me of what the change happen (i.e., 'convert to &', 'remove punctuation' or 'both')

 

Could you please give me some suggestion about this?

Thanks for your attention to this matter.

 

 

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Can you please post a sample data of what you HAVE and WANT?

Reeza
Super User

@Alexxxxxxx wrote:

Hello,

 

In a  company name standardisation process, I expect to 'Convert “AND”, “ET”, “Y”, “UND” and so on, to “&”.  and Remove all other punctuation.'

 

So, I would like to do it by following steps,

1. split a variable into several independent variables.

2. Convert “AND”, “ET”, “Y”, “UND” and so on, to “&”.

3. Remove all other punctuation.

4. merge them together ( both keep the original variable and new variable).

5. create a new variable to remind me of what the change happen (i.e., 'convert to &', 'remove punctuation' or 'both')

 

Could you please give me some suggestion about this?

Thanks for your attention to this matter.

 

 


1. SCAN(), SUBSTR() or PRX()

2. TRANWRD()

3. COMPRESS()

4. CATT()

5. No idea. 

 

Check character functions here:

https://documentation.sas.com/?docsetId=nlsref&docsetTarget=p0ydidiqibf0vbn1jljj1cv9men9.htm&docsetV...

PGStats
Opal | Level 21

Use prxChange:

 

data _null_;
length text newText $64;
do text = "Procter and Gamble", "Greyhound Lines", "Moët et Chandon";
    newText = prxChange("s/\b(AND|ET|Y|UND)\b/&/io", -1, text);
    put (_all_) (=);
    end;
run;
text=Procter and Gamble newText=Procter & Gamble
text=Greyhound Lines newText=Greyhound Lines
text=Moët et Chandon newText=Moët & Chandon

Compare text and newText to detect any change.

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 603 views
  • 3 likes
  • 4 in conversation