/* Something like the following will run dynamically depending on the records in the Location table. Notice the commented query, if you want you could use the Location_Name for the name of the generated output tables; This is one of the generated queries it will run: MPRINT(PROCESS): create table Sum_qw as select column1, sum( column2 ) as scolumn2 from qw group by column1; MPRINT(PROCESS): quit; */ * Given a similar Location table; data Location; id = 1; Location_Name = 'London '; SAS_Name = 'qw'; output; id = 2; Location_Name = 'Chicago '; SAS_Name = 're'; output; id = 3; Location_Name = 'Las Vegas'; SAS_Name = 'wd'; output; id = 4; Location_Name = 'Tokyo '; SAS_Name = 'ft'; output; id = 5; Location_Name = 'New York '; SAS_Name = 'gt'; output; run; proc sql noprint; select SAS_Name into :SAS_Name_List separated by ' ' from location order by id; quit; proc sql print; select translate( trim( substr( Location_Name, 1, 28 ) ), '_', ' ' ) into :Location_Name_List separated by ' ' from location order by id; quit; %macro process; %let i = 1; %let SAS_Name = %scan( &SAS_Name_List, &i ); %let Location_Name = %scan( &Location_Name_List, &i ); %do %until( &SAS_Name = ); proc sql; create table Sum_&SAS_Name as select column1, sum( column2 ) as scolumn2 from &SAS_Name group by column1; quit; /* proc sql; create table Sum_&Location_Name as select column1, sum( column2 ) as scolumn2 from &SAS_Name group by column1; quit; */ %let i = %eval( &i + 1 ); %let SAS_Name = %scan( &SAS_Name_List, &i ); %let Location_Name = %scan( &Location_Name_List, &i ); %end; %mend; %process;
... View more