I've searched and searched, but I can't seem to find a solution.
I'm on 8.2 Update 4 (8.2.4.1261) (32-bit).
Can someone help me export a table into an Excel file with multiple sheets?
Example: Table contains a list of USA professional sports teams (with their city/nickname and league they are in). Each tab would be separated by league (NBA, MLB, NFL, NHL, MLS). How would I go about this?
I'd also like to add the current date to the output Excel file name. From what I've read, I can create a variable with the sysdate. Just not sure how to incorporate it in the code.
BY
statement to specify the variable(s) that form a group -- in your case, it is the one variable league
BY
statement makes special tokens available during output, #BYVAR<n>
and #BYVAL<n>
league
to be important (sheet name) during output so #BYVAL1
ODS EXCEL
sheet name construction is specified in the OPTIONS
option. You can use the BY
token in the option.
ODS EXCEL... OPTIONS (sheet_name="#BYVAL1")...;
BY
statement in output procedures produces an extra line <BYVAR>=<BYVAL>
which would be noise in your Excel output.
OPTIONS NOBYLINE;
Example:
ods excel file='output.xlsx' options(sheet_name="#BYVAL1");
options nobyline;
proc print noobs data=sashelp.cars;
by make;
run;
ods excel close;
Produces
More
If you want the BY
variable to appear in the PROC PRINT
output use a VAR _ALL_;
statement, or list the columns wanted explicity.
Adding the BY
variable to the output will make things easier if you need to import and combine data that was edited in Excel, or if you are making various charts and such. In reality you might be better of producing a single worksheet with all the data and then using autofilter (which is an ODS EXCEL
option) and Excel pivot tables/charts if you are doing other work in Excel. (Proc TABULATE
and REPORT
can do a very large subset of what pivot tables can do.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.