I think this is headed in the right direction with CALL EXECUTE. I imagine the final destination is more like this:
proc freq data=MatchedLeads;
tables campaigngroup_name / out=OutFreq (rename=(campaigngroup_name=Selector) keep=campaigngroup_name) ;
run;
data _null_;
set outfreq;
call execute('data subset; set MatchedLeads;');
call execute('where campaigngroup="' || selector || '"; run;');
call execute('proc export data=subset outfile=');
call execute('"\\sysdir\' || trim(selector) || '.xlsx" dbms=xlsx replace; run;');
run;
... View more