SAS macro to combine dataset
Source:    Publish Time: 2012-09-30 04:24   1732 Views   Size:  16px  14px  12px
Author: Xuanqian Xie, Certified Advanced Programmer for SAS 9/*SAS macro to combine dataset, vertical and horizontal com

Author: Xuanqian Xie, Certified Advanced Programmer for SAS 9

/*SAS macro to combine dataset, vertical and horizontal combinations*/

/*one dimension, vertical combinations*/

%macro combine ;

data ccc;

    set %do d=1 %to 5;

      bb&d %end;

      ;

run;

%mend combine;

 

/*two dimensions, vertical combinations*/

%macro combine ;                                                                                                                       

data ccc;                                                                                                                               

 set %do i = 1 %to 10;                                                                                                                 

   %do j=1 %to 20;                                                                                                                      

  bb&i._&j %end; %end;;                                                                                                                

run;                                                                                                                                    

%mend combine;                                                                                                                         

 

/*horizontal combinations*/

%macro bb;

%do i= 1 %to 10;

%do n= 1 %to 20;

 

data aa&i._&n;

ID="ID";

xy&i._&n=&i*&n;

run;

 

%end;

%end;

%mend bb;

 

%bb;

 

%macro combine2 ;                                                                                                                       

data ddd;                                                                                                                              

 merge %do i = 1 %to 10;                                                                                                                  

   %do j=1 %to 20;                                                                                                                     

  aa&i._&j %end; %end;;

by id;

run;                                                                                                                                   

%mend combine2;                                                                                                                          

%combine2;