Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created March 23, 2021 18:54
Show Gist options
  • Save statgeek/250462887998a9591972ae3a7baaeea3 to your computer and use it in GitHub Desktop.
Save statgeek/250462887998a9591972ae3a7baaeea3 to your computer and use it in GitHub Desktop.
SAS - ODS Example using BY group to split data to separate sheets
/*This is an example of exporting data to excel, with each section going to a
separate sheet and each sheet taking the name of the group*/
*sorts your data to use BY logic;
proc sort data=sashelp.cars out=cars;
by origin;
run;
*removes proc title and by line which are usually printed by default;
ods noptitle;
options nobyline;
*sets file options - notice use of #BYVAL1 in Sheet Name to control sheet names;
ods excel file='/home/fkhurshed/ODS_Example1.xlsx' style=meadow
options(sheet_interval = "BYGROUP" sheet_label = " " sheet_name="#Byval1");
*displays data in Excel sheet;
proc print data=cars;
by origin;
run;
*closes file;
ods excel close;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment