BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

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

SASuserlot_0-1679874353546.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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.

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

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.

SASuserlot
Barite | Level 11

Thank you very much. It served my purpose.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1284 views
  • 1 like
  • 2 in conversation