data have; infile cards; input hatch source $ Value $; cards; 1 A this 2 A that 1 B here 2 C there ; proc sql noprint; select distinct hatch into:hatches separated by ' ' from have; select distinct source into:sources separated by ' ' from have; quit; %macro splitData(hatches=, sources=, basename=); %do i=1 %to %sysfunc(countw(&hatches)); %do j=1 %to %sysfunc(countw(&sources)); %let hat=%scan(&hatches,&i); %let src=%scan(&sources,&j); data &basename&hat&src; set have; where hatch=&hat and source="&src"; run; %let obs=; data _null_; if _n_=1 then set &basename&hat&src nobs=nobs; call symputx('obs',nobs); run; %if &obs>0 %then %do; proc export outfile="&basename&hat&src..dbf" dbms=dbf replace; run; %end; %end; %end; %mend; %splitData(hatches=&hatches, sources=&sources, basename=test) /* I add %let obs=; data _null_; if _n_=1 then set &basename&hat&src nobs=nobs; call symputx('obs',nobs); run; %if &obs>0 %then %do; … %end; to your code */
... View more