Send SAS Output to Excel

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 10% off till Sept 25, 2017
- Batch starts from October 8, 2017

This tutorial explains how to send SAS results (output) to Excel.

Example 1 :

Create a new sheet for each unique value in the grouping variable (By Group)
ods tagsets.excelxp file="C:\Users\Deepanshu\test.xls"
options(embedded_titles="yes"
autofilter="1-3"
frozen_headers="3"
frozen_rowheaders="1"
absolute_column_width="8.5,11,7,9,8,8"
autofit_height="yes"
sheet_interval="bygroup"sheet_label=" "
suppress_bylines="yes") style=normal;

proc print data=sashelp.shoes noobs;
title "Detail of Region #byval(region)";
by region;
run;

ods tagsets.excelxp close;
Create Multi-Sheet Excel File
The SHEET_INTERVAL= option is used to define the interval in which to create new worksheets.

Example 2 :

Define names of sheets manually 
ods tagsets.excelxp file='C:\Users\Deepanshu\Documents\multitable.xls' style=STATISTICAL
options(sheet_name='Summary' skip_space='1,0,0,0,1' EMBEDDED_TITLES='yes' sheet_interval='none');

Title " First File";
proc freq data = sashelp.class;
table sex;
run;

Title " Second File";
proc print data = sashelp.cars;
run;

ods tagsets.excelxp options(sheet_name='FREQ' skip_space='1,0,0,0,1' EMBEDDED_TITLES='yes' sheet_interval='none');
Title " Third File";

proc freq data = sashelp.cars;
table make;
run;

ods tagsets.excelxp close;
Example 3 :

Apply Custom Format of Excel
data temp;
pct= 0.75;
number= -45;
run;

ods tagsets.excelxp file="C:\Users\Deepanshu\temp.xls";

proc print data=temp noobs;
var pct;
var number / style(data)={tagattr="format:$#,##0_);[Red]($#,##0)"};
format pct percent5.2;
run;

ods tagsets.excelxp close;
Excel's Custom Format via SAS
Important Note
ODS TAGSETS.EXCELXP does not support graphs (charts). From SAS 9.4, SAS added new ODS called ODS EXCEL that supports both graphs and tables.

ODS EXCEL
ods excel file="c:\test.xlsx"
options(start_at="B5“
tab_color="red"
absolute_row_height="15"
embedded_titles="yes");

ods text="Sales report for company X";
proc print data=sashelp.orsales;
title "Sample title showing new
features";
run;

ods excel close;
ODS Excel- PROC MSChart
proc sql;
create table summary as
select(region), sum(sales) format=dollar14.2 as sales
from sashelp.shoes
group by region;
run;
quit; 
ods excel file="c:\temp.xlsx";
title "Sales by Region";
proc mschart data=work.summary category=region width=4in position="$D$1";
where region in("Africa","Asia","Canada","Pacific","United States");
vcolumn sales;
run;
ods excel close; 

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

1 Response to "Send SAS Output to Excel"

Next → ← Prev