Continuing to PROC SPELL: The Spell of SAS PART -1, this is part 2 for making proc spell more comfortable.
Lets take some example to understand how proc spell works.
First create a misspelled file :
Industries understand special traininng needs
Industry understand special training needs
Industrys understund special traininng needs
industri understand spesial training needs
indastry usderstand special training needs
industre undarstund special trainng needs
You should not trast anyone blindly
Now import this SAS file in a SAS system:
%let location = M:\sasfolder\SAS files;
libname data "&location.";
filename sample "&location.\misspelled file.txt";
Now to create a catalogue of words in the file
Proc SPELL words = sample
Create dict = data.mycatgalog.Spell;
Run;
Now initiate a file for accommodating required output :
Proc Printto print = "&location.\output.txt" new;
Run;
/* Now with the help of Proc Spell, we try to identify the misspelled words and seek suggestion to correct those, and take output in the above initialized file */
Proc Spell in = sample
dictionary = data.mycatgalog.Spell
verify suggest;
run;
Proc Printto print = print; Run;
/* Open the output file to understand the output of Proc Spell, let's get the output back into SAS */
Data data.List_correction;
infile "&location.\output.txt" missover firstobs = 7 ;
input A & $1000. ;
Run;
/* Transform the output file into readily usable form */
Data data.List_correction;
set data.List_correction;
retain id 1;
if A = "" then id +1;
Run;
Proc transpose data = data.List_correction out = data.transposed;
by id;
var A;
where A ~="";
Run;
data data.transposed;
length suggested $1000.;
retain id original_word suggested;
set data.transposed (drop = _name_);
rename Col1 = original_word;
suggested = scan(Col2,2,":"); drop col2; run;

Data data.transposed;
retain id
original_word suggested;
set data.transposed;
run;
... and here we are with a list of incorrect words with suggested correction. For few words, we might not get any and for others, we might get more than one, Now to it is time to build the further algorithm to replace wrong word with the most appropriate corrected word. You can build a macro and use tranwrd function to replace the word.
This page has taken reference from the link: SAS Gems
Lets take some example to understand how proc spell works.
First create a misspelled file :
Industries understand special traininng needs
Industry understand special training needs
Industrys understund special traininng needs
industri understand spesial training needs
indastry usderstand special training needs
industre undarstund special trainng needs
You should not trast anyone blindly
Now import this SAS file in a SAS system:
%let location = M:\sasfolder\SAS files;
libname data "&location.";
filename sample "&location.\misspelled file.txt";
Now to create a catalogue of words in the file
Proc SPELL words = sample
Create dict = data.mycatgalog.Spell;
Run;
Now initiate a file for accommodating required output :
Proc Printto print = "&location.\output.txt" new;
Run;
/* Now with the help of Proc Spell, we try to identify the misspelled words and seek suggestion to correct those, and take output in the above initialized file */
Proc Spell in = sample
dictionary = data.mycatgalog.Spell
verify suggest;
run;
Proc Printto print = print; Run;

Data data.List_correction;
infile "&location.\output.txt" missover firstobs = 7 ;
input A & $1000. ;
Run;
/* Transform the output file into readily usable form */
Data data.List_correction;
set data.List_correction;
retain id 1;
if A = "" then id +1;
Run;
Proc transpose data = data.List_correction out = data.transposed;
by id;
var A;
where A ~="";
Run;
length suggested $1000.;
retain id original_word suggested;
set data.transposed (drop = _name_);
rename Col1 = original_word;
suggested = scan(Col2,2,":"); drop col2; run;

Data data.transposed;
retain id
original_word suggested;
set data.transposed;
run;
... and here we are with a list of incorrect words with suggested correction. For few words, we might not get any and for others, we might get more than one, Now to it is time to build the further algorithm to replace wrong word with the most appropriate corrected word. You can build a macro and use tranwrd function to replace the word.
This page has taken reference from the link: SAS Gems