%macro union_tables(tab_list= sashelp.class sashelp.class);
* get number of table in list;
%let Tab_cnt=%eval(%sysfunc(countc(strip(&tab_list), %str( )))+1);
* set first table flag to 0, we are setting it to 1 where table exist first time;
%let first_tab=0;
* Proc sql begins;
proc sql;
/*Loop throught list of tables*/
%do i=1 %to &Tab_cnt;
%let tab=%sysfunc(scan(&tab_list,&i,%str( )));
%if %sysfunc(exist(&tab)) %then %do; /*Check if table exist*/
%if &first_tab=0 %then %do; /*Check if this is first table that exist*/
%let first_tab=1; /*Set value flag to 1*/
create table out_tab as /*Add create tastemet for first table which exist*/
%end;
%else %do; union all %end; /*if this is second or other table that exists*/
select * from &tab /*Select statment*/
%end;
%end;
;
quit ;
%mend;
options mlogic symbolgen mprint;
%union_tables(tab_list= sashelp.class sashelp.class)
... View more