Back to Tech Corner
SAS Programming

Creating several customized sheets in Excel workbook using SAS

The following code example creates two sheets (tabs) in a single workbook. In addition, it demonstrates some other features to enhance data visualization.

/* -------------------------------------------- */
/* Two sheets workbook with enhanced appearance */
/* -------------------------------------------- */
/* Formats for background & foreground coloring */
proc format;
value hbg
50 <- 60 = #66FF99
60 <- 70 = #FFFF99
70 <- high = #FF6666
;
value hfg
low -< 50, 70 <- high = white;
run;

/* Define custom font style for ODS TEXT */
proc template;
define style styles.MyStyle;
parent=styles.htmlblue;
style usertext from usertext /
foreground = #FF33CC
font_weight = bold
;
end;
run;

/* ODS Excel output file destination */
ods excel file = 'E:\Asif\BlogRepo\Two_sheets_fancy.xlsx';

/* Excel options for 1st sheet (tab) */
ods excel options
( sheet_name = 'SASHELP.CLASS'
frozen_headers = 'on'
embedded_titles = 'on' )
style = styles.MyStyle;

title justify=left color='#4D7EBF' 'This is TITLE for SASHELP.CLASS';
ods text='This is TEXT for SASHELP.CLASS';

proc print data=SASHELP.CLASS noobs;
var NAME;
var SEX AGE / style = {just=C};
var HEIGHT / style = {background=hbg. foreground=hfg.};
var WEIGHT;
run;

/* Excel options for 2nd sheet (tab) */
ods excel options
( sheet_name = 'SASHELP.CARS'
frozen_headers = 'on'
embedded_titles = 'on' );

title 'This is TITLE for SASHELP.CARS';

proc print data=SASHELP.CARS noobs;
run;

ods excel close;
/* End Program */

Reference link: https://blogs.sas.com/content/tag/sas-programming/