BookmarkSubscribeRSS Feed
jiangmi
Calcite | Level 5

Hi, All,

Is there a way that we can append results from macro runs to multiple tabs in one single excel file?

Take an example like below, each time the macro run, new output will replace the old. However, I want both results to be present in one excel file (picture show).

I also tried ODS TAGSETS, it doesn't seem to work either.  Please offer opinions. Thanks. Joe

data have1;

sex='M';run;

data have2;

sex='F';run;

%macro test (data, var);

proc export

data=&data (where=(sex="&var"))

outfile="/SASData/SASUSER/Range/why2.xlsx"

dbms=xlsx replace;

sheet="&var";

run;

%mend test;

%test(have1, M)

%test(have2, F)

bothinexcel.JPG

4 REPLIES 4
Reeza
Super User

Try DBMS=ExcelCS

You can do it using XLSX if you have SAS 9.4 or applied a hot fix to SAS 9.3

jiangmi
Calcite | Level 5

What kind of hotfix?

Reeza
Super User

Hot Fixes for SAS/ACCESS Interface to PC Files 9.3_M1

The XLSX engine is enhanced to write multiple sheets per Microsoft Excel file in the first maintenance release of SAS® 9.3 (TS1M1)


I don't know if you have 9.3TS1M2 if this would be fixed or not.


At any rate, tagsets.excelxp will definitely work, but it's a different structure for the code.


Untested, but it would be something like the following:



data have1;

sex='M';run;

data have2;

sex='F';run;

%macro test (data, var);

options tagsets.excelxp(sheet_name="&var");

proc print data=&data (where=(sex="&var"));

run;

%mend test;

ods tagsets.excelxp file="C:\temp\out.xlsx" style=journal;

%test(have1, M)

%test(have2, F)

ods tagsets.excelxp close;

jiangmi
Calcite | Level 5

Thanks, Reeza,

I actually read your old post on the same issue:

I am running SAS EG on server, I don't have install privilege either.


The ' DBMS=ExcelCS' doesn't seem to work.

Putting macros in ods tagsets isn't promising either, after copying pasting the code and several modification tries.

It may has something to do with my connection to the server, cause I got error msg like 'ERROR: Server Name is invalid or missing.'. I will surely try them on my local SAS later today.

Thanks again.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 1525 views
  • 0 likes
  • 2 in conversation