Hi! I have a dataset that has more than 10000 rows and need to export this dataset to excel workbooks where each workbook represents one country. The total number of countries is 29. For each country, there are events. I also would like to have one event in each tab inside one excel workbook. I tried this code but it does not work. %macro export_to_excel; PROC SQL noprint; SELECT DISTINCT VENUE_COUNTRYCODE3 INTO :country1-:country99 FROM WORK.datafile; %let numCountries = &SQLOBS; QUIT; %do i = 1 %to &numCountries; %let country = &&country&i; ods excel file="filepath&country..xlsx"; PROC SQL noprint; SELECT DISTINCT EVENT INTO :event1-:event999 FROM WORK.datafile WHERE COUNTRY = "&country"; %let numEvents = &SQLOBS; QUIT; %do j = 1 %to &numEvents; %let event = &&event&j; %let startdate = &&startdate&j; %let sheetname = %sysfunc(tranwrd(&event, %str( ), _)); ods excel options(sheet_name="&sheetname"); PROC REPORT DATA=WORK.datafile; WHERE COUNTRY = "&country" AND EVENT = "&event"; COLUMN EVENT START_DATE END_DATE CLIENT_FIRST_NAME CLIENT_LAST_NAME ADDRESS; RUN; %end; ods excel close; %end; %mend export_to_excel; %export_to_excel; Thanks!
... View more