Something more like the following. This would be more useful after adding parameters to the macro to reference things like the dataset names and your other macro variables. %macro country ; %local Countries NumCountries I Country; proc sql noprint; select distinct country into :Countries separated by ' ' from <your dataset name with countries goes here>; quit; %let NumCountries = %sysfunc(countw(&Countries,' ,')); %do i = 1 %to &numcountries; %let Country = %scan(&countries,&i); proc sql; title1 "2007 &Country Customer Purchases"; title2 "Total &Country Purchases: &Country_Purchases"; /* you didn't provide any information about where the macro variable &County_Purchases comes from so this code is likely not to work as is I would recommend testing this part to loop through the countries without it first, may have problem with &Purchases as well for same reason*/ select distinct c.Customer_Name, &Purchases as Purchases label='Purchases' format=dollar10.2 from orion.Order_Fact as o, orion.Customer as c where o.Customer_ID=c.Customer_ID and year(Order_Date)=2007 and "&Country"=c.Country group by "&Country", c.Customer_ID having &Purchases>1 order by calculated Purchases desc; quit; %end; %mend;
... View more