Some time back I have created this macro to address similar kind of need in our project . This macro takes below given parameters 1. Libname is source library 2. SAS_Data : Source SAS Table 3. Output_Name : Excelsheet Name 4. Sheet_Category : If you want to create sheets based on some criterian , use Classification variable as Sheet_Category options mprint mlogic symbolgen; %macro Send_to_Excel( libname =, SAS_data=, output_name = , Sheet_category = ); proc sql noprint; select type into :cat_type from DICTIONARY.COLUMNS where upcase(name) = upcase("&Sheet_category.") and upcase(libname) = upcase("&libname.") and upcase(memname) = upcase("&SAS_data.") ; quit; proc sql noprint; /* determine total no of sheets required to be created */ select strip(put(count(distinct(&Sheet_category)),best2.)) into :tot_cat_cnt from &libname..&sas_data; select distinct &Sheet_category into :idcat1 - :idcat&tot_cat_cnt from &libname..&sas_data; %let catcnt = &sqlobs; quit; /* Create Excel file in DMM_TEMP Folder */ %do i = 1 %to &tot_cat_cnt; proc export data=&libname..&sas_data (where=(&Sheet_category = %if &cat_type = char %then "&&idcat&i"; %else &&idcat&i; )) OUTFILE="&output_name..xls" DBMS= xls REPLACE; sheet = "A_&&idcat&i"; RUN; %end; %mend Send_to_Excel; %Send_to_Excel(libname = sashelp, SAS_data=class, output_name = Amol, Sheet_category = sex );
... View more