Hello, Starting from this subject: https://communities.sas.com/t5/SAS-Programming/How-to-create-columns-with-values-based-on-occurence-of-words/td-p/595563/highlight/true, I wanted to solve it with regular expressions (just a challenge for me). Passing parametres seems to me not to work. Could you help me. Thank you: data variables;
infile datalines delimiter=',' dsd;
length cars $6 vegetables $12 regions $14;
input cars $ vegetables $ regions $;
datalines;
Audi,beans,America
BMW,black beans,Central Europe
BMW X5,carrot,East Europe
X5,chili pepper,Europe
Honda,green beans,North America
,lettuce,South America
,onion,
,pepper,
;
run;
data test ;
input var $30.;
cards ;
Ford carrot
Honda beans
south america black beans
green beans Audi
x5 chili pepper lettuce
garlic north America
central europe bmw
lettuce onion X5
America pepper
X5 BMW Europe
Central East Europe
bmw X5 america
;
run ;
proc sql;
select distinct cars , length(cars) as maxcar into: cars separated by '|'
from variables where cars ne "" order by maxcar desc;
select distinct vegetables , length(vegetables) as maxvege into: vege separated by '|'
from variables where vegetables ne "" order by maxvege desc;
select distinct regions , length(regions) as maxregion into: region separated by '|'
from variables where regions ne "" order by maxregion desc;
%put &cars;
%put &vege;
%put ®ion;
option mlogic mprint ;
%macro tt();
data test1 (drop=patt: START LENGTH);
set test;
%let PATTERN1 = %sysfunc(PRXPARSE("/&cars/i"));
%let PATTERN2 = %sysfunc(PRXPARSE("&vege/i"));
%let PATTERN3 = %sysfunc(PRXPARSE("/®ion/i"));
length var1 $8;
%do i=1 %to 3;
%syscall PRXSUBSTR (&&PATTERN&i,var,START,LENGTH));
%IF START GT 0 %THEN %DO;
var&i = SUBSTR(var,START,LENGTH);
%end;
%else %do;
var&i="";
%end;
%end;
output;
run;
%mend tt;
%tt;
... View more