These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/*Create data set of valid magazine names.*/
data mags;
input title $char30.;
datalines;
Science
Discover
Nature Today
Journal of Medicine
Outside
;
run;
/*Create data set of articles with magazine name. Some of the magazine names are not quite correct.*/
data articles;
infile datalines dlm=',';
input magtitle :$30. article :$30.;
datalines;
Science, Bears
Sciene, Cats
Sciences, Dogs
Discovery, Stars
Discover, Planets
Outdoors, Hiking
;
/*Generate two output data sets: MATCH if the magazine names are an exact match and */
/*CLOSE if the distance between the magazine names is within the value we have set.*/
/*First, we read in all the correct magazine titles from the MAGS data set into an array.*/
/*Then we read through each observation in the data set ARTICLES. If the magazine names*/
/*are an exact match, we output to MATCH and stop checking for a magazine. If COMPLEV returns*/
/*a distance of less than or equal to 5 (chosen arbitrarily to get matches we consider*/
/*"close enough"), then the observation is written to the CLOSE data set.*/
data match (keep = magtitle article)
close (keep=distance magtitle possible_mag article);
array mags[5] $20 _temporary_;
do until (done);
set mags end=done;
count+1;
mags[count] = title;
end;
do until (checkdone);
set articles end=checkdone;
do i = 1 to dim(mags);
distance = complev(magtitle, mags[i],'iln');
if distance=0 then do;
output match;
leave;
end;
else if distance <= 5 then do;
possible_mag = mags[i];
output close;
end;
end;
end;
stop;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Data set MATCH:Obs magtitle article 1 Science Bears 2 Discover PlanetsData set CLOSE:possible_ Obs magtitle article distance mag 1 Sciene Cats 1 Science 2 Sciences Dogs 1 Science 3 Discovery Stars 1 Discover 4 Outdoors Hiking 5 Outside
Type: | Sample |
Topic: | Common Programming Tasks ==> Combining Data Common Programming Tasks ==> Working with Character Data SAS Reference ==> Functions ==> Character String Matching SAS Reference ==> Functions ==> Character ==> COMPGED SAS Reference ==> Functions ==> Character ==> COMPLEV |
Date Modified: | 2012-12-11 15:43:40 |
Date Created: | 2012-12-02 11:06:43 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | Base SAS | Solaris for x64 | 9.21 | 9.2 TS2M0 | ||
OpenVMS on HP Integrity | 9.21 | 9.2 TS2M0 | ||||
Linux for x64 | 9.21 | 9.2 TS2M0 | ||||
Linux | 9.21 | 9.2 TS2M0 | ||||
HP-UX IPF | 9.21 | 9.2 TS2M0 | ||||
64-bit Enabled Solaris | 9.21 | 9.2 TS2M0 | ||||
64-bit Enabled HP-UX | 9.21 | 9.2 TS2M0 | ||||
64-bit Enabled AIX | 9.21 | 9.2 TS2M0 | ||||
Windows Vista for x64 | 9.21 | 9.2 TS2M0 | ||||
Windows Vista | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows XP Professional | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2008 for x64 | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 for x64 | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Standard Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Enterprise Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Datacenter Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft® Windows® for x64 | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows XP 64-bit Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.21 | 9.2 TS2M0 | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.21 | 9.2 TS2M0 | ||||
z/OS | 9.21 | 9.2 TS2M0 |