I have two datasets with the same variables and the same formats. How to export them into one excel file with different sheets. Is there any simple way, or do I have to write ODS EXCEL ( or TAGSETS) with PORC REPORT for each dataset? Thank you for your input.
In the following example, is there any way I can create a macro and loop the required datasets? The following is simple export
data class1;
set sashelp.class;
run;
data class2;
set sashelp.class;
run;
PROC EXPORT DATA= WORK.class1
OUTFILE= "D:\Desktop\classes.xls"
DBMS=EXCEL REPLACE;
SHEET="Class1"; /* for class2 I have to run it again*/
NEWFILE=YES;
RUN;
This is how I want two sheets in one excel file
It's a lot easier if you use the XLSX LIBNAME:
data class1;
set sashelp.class;
run;
data class2;
set sashelp.class;
run;
libname CLASS XLSX "<MyDir>\Class.xlsx";
proc datasets library = CLASS;
copy in = WORK out = CLASS;
select class1 class2;
run;
quit;
libname CLASS clear;
No loop needed.
It's a lot easier if you use the XLSX LIBNAME:
data class1;
set sashelp.class;
run;
data class2;
set sashelp.class;
run;
libname CLASS XLSX "<MyDir>\Class.xlsx";
proc datasets library = CLASS;
copy in = WORK out = CLASS;
select class1 class2;
run;
quit;
libname CLASS clear;
No loop needed.
Thank you very much. It served my purpose.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.