I've been looking online and i've seen the ods "oxford english language dictionary" excel documentation but i don't know enough to really use it. What i want to do is this:
* sheet 1;
proc contents data=file1; set=contents (keep=varnum name);
proc sort data=contents; by varnum;
ods excel file=varlistf1;
proc print data=contents;
run;
ods excel close;
repeat for file2-10, writing to sheets 2-10;
I know there is a sheet name (or sheetname) subcommand to name the sheets and i'd like to do that. But, i'll just bet there's a problem because, i'll bet, each 'write' for file1-10 goes to sheet1 and overwrites whatever is there.
Thanks, Gene Maguin
If you place all of your Proc Print calls within the same Ods excel / ods excel close "sandwich" each proc print will be on a separate sheet:
Example:
ods excel file= outfile; proc print data=sashelp.class; run; proc print data=sashelp.class; run; ods excel close;
assuming outfile is a legitimate file reference will print the same data set twice, once on each of two sheets.
If you have 20 proc prints then you should get 20 sheets.
Sorry, but i hardly understand what you are trying to do.
If you want the output of multiple procedure on a single worksheet, use sheet_interval = "none" to disable the default behaviour of using a new worksheet for each procedure. If you need multiple files with multiple sheets, you won't be able to achieve this by using ods excel alone, but you will find some hints and code by using the search-function of the community - this topic has been discussed recently.
If you place all of your Proc Print calls within the same Ods excel / ods excel close "sandwich" each proc print will be on a separate sheet:
Example:
ods excel file= outfile; proc print data=sashelp.class; run; proc print data=sashelp.class; run; ods excel close;
assuming outfile is a legitimate file reference will print the same data set twice, once on each of two sheets.
If you have 20 proc prints then you should get 20 sheets.
I know there is a sheet name (or sheetname) subcommand to name the sheets and i'd like to do that. But, i'll just bet there's a problem because, i'll bet, each 'write' for file1-10 goes to sheet1 and overwrites whatever is there.
Can you please clarify what you mean here? Are you betting that there's problems or are you actually encountering errors? What's an actual use case for you?
You can generate multiple worksheets per workbook by using BY group processing automatically, but if you want multiple files you need to either create a macro or have unique code to create each file.
Quick example that produces 2 files from the SASHELP.BASEBALL dataset:
%let path=/folders/myfolders/ODS Excel examples/;
ods excel file="&path.one_sheet_per_city.xlsx"
options(sheet_name="#byval(team)"
index='on'
embedded_titles='on'
frozen_headers='on');
proc sort data=sashelp.baseball
out=sorted_by_team;
by team;
run;
options nobyline;
proc print data=sorted_by_team noobs;
title "#byval(team) players in 1986";
by team;
pageby team;
run;
ods excel close;
proc sort data=sorted_by_team
out=sorted_by_league_division;
by league division name;
run;
ods excel file="&path.one_sheet_per_league_and_division.xlsx"
options(sheet_name="#byval(league) #byval(division)"
index='off'
embedded_titles='on'
frozen_headers='on'
start_at='2,2'
autofilter='all');
proc print data=sorted_by_league_division noobs;
title "Players listed in #byval(league) #byval(division) in 1986";
by league division;
pageby division;
run;
ods excel close;
I'd suggest searching on "ods excel Chevell Parker" to get a bunch of papers with examples, and a few videos of his talks.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.