BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chandan_mishra
Obsidian | Level 7

Hello

 

I want to export all the tables from work library in excel format with dataset names as sheet names:

 

%let path = "C:\Users\Data";



PROC EXPORT DATA= Data1 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='Data1';
RUN;


PROC EXPORT DATA= SecondData OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='SecondData';
RUN;



PROC EXPORT DATA= Data3 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET=''Data3";
RUN;

As can be seen, I have to write the same code multiple times to export the data in the same excel file with dataset name as sheet names. Is there any way, I can write one Proc export and just export all the datasets available in the work library in the excel format with dataset names as sheet names.

 

Thanks

Chandan Mishra

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Yes, use a libname instead to create the Excel file and PROC COPY to copy the data sets from the input library, WORK in your example, to the new file, outfile. 

 

libname outfile xlsx "&path.\Forecast.xlsx";

proc copy in=work out=outfile;
run;

libname outfile;

@chandan_mishra wrote:

Hello

 

I want to export all the tables from work library in excel format with dataset names as sheet names:

 

%let path = "C:\Users\Data";



PROC EXPORT DATA= Data1 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='Data1';
RUN;


PROC EXPORT DATA= SecondData OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='SecondData';
RUN;



PROC EXPORT DATA= Data3 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET=''Data3";
RUN;

As can be seen, I have to write the same code multiple times to export the data in the same excel file with dataset name as sheet names. Is there any way, I can write one Proc export and just export all the datasets available in the work library in the excel format with dataset names as sheet names.

 

Thanks

Chandan Mishra


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Yes, use a libname instead to create the Excel file and PROC COPY to copy the data sets from the input library, WORK in your example, to the new file, outfile. 

 

libname outfile xlsx "&path.\Forecast.xlsx";

proc copy in=work out=outfile;
run;

libname outfile;

@chandan_mishra wrote:

Hello

 

I want to export all the tables from work library in excel format with dataset names as sheet names:

 

%let path = "C:\Users\Data";



PROC EXPORT DATA= Data1 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='Data1';
RUN;


PROC EXPORT DATA= SecondData OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET='SecondData';
RUN;



PROC EXPORT DATA= Data3 OUTFILE="&path.\Forecast.xlsx" DBMS=xlsx REPLACE;
SHEET=''Data3";
RUN;

As can be seen, I have to write the same code multiple times to export the data in the same excel file with dataset name as sheet names. Is there any way, I can write one Proc export and just export all the datasets available in the work library in the excel format with dataset names as sheet names.

 

Thanks

Chandan Mishra


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 6477 views
  • 2 likes
  • 2 in conversation