proc format;
value classa
1='ADATA'
2='BDATA'
;
value classb
1='CDATA'
2='DDATA'
;
run;
data in;
length class_a class_b $ 8;
do i=1 to 2;
do j=1 to 2;
class_a=trim(left(put(i,classa.)));
class_b=trim(left(put(j,classb.)));
someVar=ranuni(0);
someOtherVar=ranuni(0);
output;
end;
end;
run;
options mprint symbolgen mlogic;
%macro separate(dsn=, classvar1=, classvar2=);
proc sql;
select distinct trim(left(&classvar1)) || '_' || trim(left(&classvar2))
into :dsnames separated by ' '
from &dsn;
quit;
data &dsnames.;
set &dsn;
%let idx=1;
%let thiscombo=%sysfunc(scan(&dsnames,&idx,%str( )));
%do %while(%length(&thiscombo) > 0);
IF ( &classvar1 = %sysfunc(quote(%sysfunc(scan(&thiscombo,1,%str(_))))) AND
&classvar2 = %sysfunc(quote(%sysfunc(scan(&thiscombo,2,%str(_))))) )
THEN OUTPUT &thiscombo;
%let idx=%eval(&idx+1);
%let thiscombo=%sysfunc(scan(&dsnames,&idx,%str( )));
%end;
run;
%mend;
%separate(dsn=in, classvar1=class_a, classvar2=class_b);