BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

Hi Guys,

I want to spelling correction in existing data 

 

 

data trns;

x='JAPON';

m=translate('x','O','A');

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @BrahmanandaRao 

 

You are not translating the value of variable X, but the literal string 'x', because you have the variable name in quotes, so the translate function does not see it as a variable.

 

And remember the translate function has the arguments reversed compared to human logic: Translate(Variable, TO, FROM), so you get JOPON, where I guess you would want JAPAN. - The Tranwrd function has the arguments in logic order.

 

Try this, you get JAPAN in both new variables:

data trns;
	x='JAPON';
	m=translate(x,'A','O');
	n=tranwrd(x,'O','A');
run;

 

 

 

 

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

@BrahmanandaRao wrote:

Hi Guys,

I want to spelling correction in existing data 

 

 

data trns;

x='JAPON';

m=translate('x','O','A');

run;


You already have working code. Where is the problem?

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @BrahmanandaRao 

 

You are not translating the value of variable X, but the literal string 'x', because you have the variable name in quotes, so the translate function does not see it as a variable.

 

And remember the translate function has the arguments reversed compared to human logic: Translate(Variable, TO, FROM), so you get JOPON, where I guess you would want JAPAN. - The Tranwrd function has the arguments in logic order.

 

Try this, you get JAPAN in both new variables:

data trns;
	x='JAPON';
	m=translate(x,'A','O');
	n=tranwrd(x,'O','A');
run;

 

 

 

 

BrahmanandaRao
Lapis Lazuli | Level 10

Thank your very much for your support 

what if multiple spelling corrections in existing data

 


data mulspell;
input country$12.;
datalines;
Australia
Newzelandd
Garmany
wasington
netherlands
;
run;

 

Regards, ANAND
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @BrahmanandaRao 

 

Corrections with string functions will be impossible, because a translation that works for one name will ruin another. I do the following, which is very useful if it is a production job:

 

1. Make a table with all distinct names selected from source and sorted by name.

 

2.Export the list to excel.

 

3. Open the spreadsheet, write the correct name in column B and copy it down to all different occurrences of the same country. Note that each country should have a row with the correct name in col. A. - Save.

 

4. Read the spreadsheet into a SAS table.

 

5. Left Join the source table and the correction table on country. Now all names found in the correction table will be translated,

 

6. Make a table with distinct names where corrected_name = ''.

 

 7. If this table has zero rows, everything is OK. Otherwise you have new countries or new misspellings in your input. Add the names to your spreadsheet and rerun 4-7.

 

 

BrahmanandaRao
Lapis Lazuli | Level 10

Thank you very much for your valuable advise

 

 

Regards 

Anand

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
  • 5 replies
  • 1888 views
  • 1 like
  • 3 in conversation