BookmarkSubscribeRSS Feed
ysk
Calcite | Level 5 ysk
Calcite | Level 5

Hi SASCommunity,

 

I have an ouptut that i wish to ouput into multiple excel files based on a variable (i.e. Employee Name).

 

I have the following code so far but would like to tweak it to export it out to different excel files based on Employee name.

 

For instance, I have employee name Bob Joe and Cindy - i want ouput exported out to 3 separate excel files named after their names (i.e. Bob.xlsx, Joe.xlsx, and Cindy.xlsx). Also I want to avoid using %macro (Employee_name) because the list of employee_name changes quite often so i want to know if i can use the code below.

 

proc sort data=ouptut;
by coder;
run;

ods preferences;

ods listing close;
ods tagsets.excelxp file='local directoy\output.xml' style=sasweb
options(sheet_interval='bygroup' doc='Help');
proc print data=output noobs;
by employee_name;
var variable1 variable2 variable3;
run;
ods tagsets.excelxp close;

 

Thanks!

 

2 REPLIES 2
Reeza
Super User

Tagsets doesn't create multiple file. 

 

Create a standard proc export and use call execute within a data step to call macro rather than manual macro calls. 

 

You could probably write a single call execute with a where. 

 

First option:

 

http://blogs.sas.com/content/sgf/2014/04/18/make-your-macro-invocations-data-driven/

 

 

 

Cynthia_sas
SAS Super FREQ

Hi:

  TAGSETS.EXCELXP will do part of what you want. You CAN create a separate Excel file for every by group with this code:

 

proc sort data=sashelp.class out=newclass;
  by sex;
run;

ods tagsets.excelxp file='c:\temp\bygrp1.xml' newfile=bygroup style=htmlblue;
 
proc report data=newclass;
by sex;
run;

ods tagsets.excelxp close;

 

  Many ODS destinations support NEWFILE= (ODS EXCEL (the newest) does NOT seem to support NEWFILE=.

 

The way that NEWFILE= works is that the first file (in my case, the file for all the values of 'F' for sex), will be put into BYGRP1.XML file and all the values of 'M' will be put into BYGRP2.XML.

 

  If you truly want the names for each BY group to be part of the output file, then you will have to use the data-driven macro approach, as suggested by Reeza.

 

cynthia

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
  • 2 replies
  • 2722 views
  • 2 likes
  • 3 in conversation