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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6065 views
  • 2 likes
  • 2 in conversation