1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-03 23:50:06 +00:00

feat: adding MATCH parameter to mp_searchcols.sas to enable fuzzy matching on columns. Closes #14

This commit is contained in:
Allan Bowe
2021-05-13 21:38:38 +03:00
parent 51ddd9c1e5
commit c6b65366b7
3 changed files with 121 additions and 8 deletions

41
all.sas
View File

@@ -2945,7 +2945,7 @@ run;
proc sql;
create table data1 as select * from sashelp.class;
create view view2 as select * from sashelp.class;
%mp_dropmembers(libref=WORK, list=data1 view2)
%mp_dropmembers(data1 view2, libref=WORK)
<h4> SAS Macros </h4>
@@ -5729,7 +5729,15 @@ run;
%mp_searchcols(libs=sashelp work, cols=name sex age)
@param libs=
@param libs=(SASHELP) Space separated list of libraries to search for columns
@param cols= Space separated list of column names to search for (not case
sensitive)
@param outds=(mp_searchcols) the table to create with the results. Will have
one line per table match.
@param match=(ANY) The match type. Valid values:
@li ANY - The table contains at least one of the columns
@li WILD - The table contains a column with a name that partially matches
@version 9.2
@author Allan Bowe
**/
@@ -5737,6 +5745,7 @@ run;
%macro mp_searchcols(libs=sashelp
,cols=
,outds=mp_searchcols
,match=ANY
)/*/STORE SOURCE*/;
%put &sysmacroname process began at %sysfunc(datetime(),datetime19.);
@@ -5758,8 +5767,10 @@ create table _data_ as
%end;
order by 1,2,3;
%local tempds;
%let tempds=&syslast;
data &outds;
set &syslast;
set &tempds;
length cols matchcols $32767;
cols=upcase(symget('cols'));
colcount=countw(cols);
@@ -5773,10 +5784,29 @@ data &outds;
retain matchcols;
matchcols='';
end;
%if &match=ANY %then %do;
if findw(cols,name,,'spit') then do;
sumcols+1;
matchcols=cats(matchcols)!!' '!!cats(name);
end;
%end;
%else %if &match=WILD %then %do;
if _n_=1 then do;
retain wcount;
wcount=countw(cols);
drop wcount;
end;
do i=1 to wcount;
length curword $32;
curword=scan(cols,i,' ');
drop curword;
if index(name,cats(curword)) then do;
sumcols+1;
matchcols=cats(matchcols)!!' '!!cats(curword);
end;
end;
%end;
if last.memname then do;
if sumcols>0 then output;
if sumcols=colcount then putlog "Full Match: " libname memname;
@@ -5786,10 +5816,11 @@ run;
proc sort; by descending sumcols memname libname; run;
proc sql;
drop table &tempds;
%put &sysmacroname process finished at %sysfunc(datetime(),datetime19.);
%mend;
/**
%mend mp_searchcols;/**
@file
@brief Searches all data in a library
@details