Here is an example using regular expressions, the code translates the A and N into the corresponding expression and then uses PRXMATCH to test
data ctry_format;
infile cards dlm=",";
input
country : $32.
zip_format : $32.
;
length prx_expression $ 128;
prx_expression = "/";
drop i;
do i = 1 to length(zip_format);
select (char(zip_format, i));
when ("N") do;
prx_expression = cats(prx_expression, "\d");
end;
when ("A") do;
prx_expression = cats(prx_expression, "[A-Z]");
end;
when (" ") do;
prx_expression = cats(prx_expression, "\x20");
end;
end;
end;
prx_expression = cats(prx_expression, "/");
cards;
Canada,ANA NAN
France,NNNNN
Switzerland,NNNN
United States,NNNNN
;
data ctry_have;
infile cards dlm=",";
input
country : $32.
zip : $32.
;
cards;
Canada,A6C 2X8
Canada,A6C-2X8
France,31360
Switzerland,123
United States,55344
United States,TW18 4BQ
;
data want;
merge ctry_format ctry_have;
by country;
prxmatch = ( prxmatch(prx_expression, trim(zip)) > 0 );
run;
Bruno
... View more