Online File

How to use this page


Rick Aster: Professional SAS Programming Shortcuts: Contents

Chapter 81
Program
Name matching


*
   Normalize East names.
*;
data work.easttext;
   set east.list;
   length nameeqv alpha $ 32;
   array word{10} $ 16;
   alpha = compress(upcase(name), "'.");
   alpha = tranwrd(alpha, '&', ' and ');
   alpha = tranwrd(alpha, '+', ' and ');
   alpha = translate(alpha, ' ', "!(),/:?-");
   alpha = left(compbl(alpha));

   do i = 1 to dim(word);
      word{i} = scan(alpha, i, ' ');
      end;
   nameeqv = '';
   do i = 1 to dim(word);
      from = word{i};
      if from = '' then leave;
      * Remove numbers. ;
      if i > 1 then 
          if not verify(from, '0123456789. ') then from = '';
      * Substitute word from thesaurus. ;
      set main.namethes key=from/unique;
      if _iorc_ then do; * Not found. ;
         _iorc_ = 0;
         _error_ = 0;
         end;
      else word{i} = to;
      if nameeqv = '' then nameeqv = word{i};
      else nameeqv = trim(nameeqv) || ' ' || word{i};
      end;
run;
proc sort data=work.easttext;
   by nameeqv alpha name;
run;

*
   Normalize West names.
*;
data work.westtext;
   set west.list;
   length nameeqv alpha $ 32;
   array word{10} $ 16;
   alpha = compress(upcase(name), "'.");
   alpha = tranwrd(alpha, '&', ' and ');
   alpha = tranwrd(alpha, '+', ' and ');
   alpha = translate(alpha, ' ', "!(),/:?-");
   alpha = left(compbl(alpha));

   do i = 1 to dim(word);
      word{i} = scan(alpha, i, ' ');
      end;
   nameeqv = '';
   do i = 1 to dim(word);
      from = word{i};
      if from = '' then leave;
      * Remove numbers. ;
      if i > 1 then 
          if not verify(from, '0123456789. ') then from = '';
      * Substitute word from thesaurus. ;
      set main.namethes key=from/unique;
      if _iorc_ then do; * Not found. ;
         _iorc_ = 0;
         _error_ = 0;
         end;
      else word{i} = to;
      if nameeqv = '' then nameeqv = word{i};
      else nameeqv = trim(nameeqv) || ' ' || word{i};
      end;
run;
proc sort data=work.westtext;
   by nameeqv alpha name;
run;

*
   Merge and print matches.
*;
data work.match;
   merge
       work.easttext (in=in1 rename=(id=id1 name=name1 alpha=alpha1))
       work.westtext (in=in2 rename=(id=id2 name=name2 alpha=alpha2))
       ;
   by nameeqv;
   if in1 and in2;
run;
title1 'Equivalent Names';
proc print data=work.match heading=horizontal;
   id id1 id2;
   var nameeqv name1 name2;
run;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Shortcuts

Contents/Online Files

Corrections

Catalog Page