Presentation is loading. Please wait.

Presentation is loading. Please wait.

Beautiful PROC CONTENTS Output Using the ODS Excel Destination

Similar presentations


Presentation on theme: "Beautiful PROC CONTENTS Output Using the ODS Excel Destination"— Presentation transcript:

1 Beautiful PROC CONTENTS Output Using the ODS Excel Destination
Suzanne Dorinski SESUG 2015 Disclaimer: Any views expressed are those of the author and not necessarily those of the U.S. Census Bureau.

2 Overview Question from in-house user group member
Solution for Oracle database Solution for library with native SAS data sets

3 Question from user How do I export the output of PROC CONTENTS (variable name, type, length, and format) from several Oracle database tables within the same database to separate worksheets (one worksheet for each table) in an Excel spreadsheet?

4 ODS Excel destination! Easy to create native Excel output
Experimental in SAS 9.4 M2 Production in SAS 9.4 M3 (July 2015 release)

5 Oracle database example
Oracle database used in example has 8 tables.

6 Connect to the Oracle database
libname asj oracle   user=asjview   password=asjview   path=jailprod.world   schema=asjdba   access=readonly; run; Contact your Oracle database administrator for the user, password, path, schema, and access parameters you should use.

7 Need to know which PROC CONTENTS output object to use
Use the ODS TRACE ON statement to find out the names of the output objects. The names will be displayed in the log. You can use the name, label, template, or path specifications.

8 Save information to data set
You use the name of the output object in the ODS OUTPUT statement. The object name is on the left of the equal sign, while the name of your data set is on the right of the equal sign.

9 Use _all_ keyword to work with all the data sets in a library
Instead of running PROC CONTENTS multiple times, the _all_ keyword will work with all the data sets in the library.

10 Sort for readability Sort by member to get the data sets in alphabetical order. Sort by num to get the variables for each data set in position order.

11 PROC PRINT produces output
Use BY and PAGEBY statements in PROC PRINT to produce one page for each table. By default, the output will have MEMBER=<data set> at the top of each page. The OPTIONS nobyline statement suppresses that default text at the top of each page. #BYVAL( ) is a special substitution, which will use the current value of the variable inside the parenthesis. The title statement in the code on the slide will show the data set name in the title statement, automatically updated on each page.

12 Add ODS sandwich options nobyline;
ODS EXCEL FILE="H:\SESUG 2015\all_variables_from_Oracle_database.xlsx" options(sheet_name="#BYVAL(member)" embedded_titles='yes'); proc print data=AllOracleVarOut noobs; by member; pageby member; title "Variables in #BYVAL(member) table"; run; ODS EXCEL CLOSE; Add the ODS sandwich to produce the output. [Cynthia Zender of SAS is the person who came up with the phrase “ODS sandwich”.] The ODS EXCEL FILE statement is just above the PROC PRINT, while the ODS EXCEL CLOSE statement is right after the PROC PRINT. The sheet_name option on the ODS EXCEL statement will specify the name for each sheet. #BYVAL(member) as the name means that each sheet will have the name of the data set it is documenting. The embedded_titles option means that the titles will show up in the body of the spreadsheet. The default is no, which means that titles show up in the headers. If you don’t print or print preview the spreadsheet, you will not see the titles if they are not embedded!

13 View the output The default style is HTMLBlue, which looks nice. This is a native Excel spreadsheet.

14 Now do with library of SAS data sets
ODS OUTPUT variables=allvarout; proc contents data=sashelp._all_ memtype=data; run; proc sort data=allvarout; by member num;

15 SAS data sets example continued
options nobyline; ODS EXCEL FILE="H:\SESUG 2015\all_variables_in_SASHELP_data_sets.xlsx" options(sheet_name="#BYVAL(member)" embedded_titles='yes'); proc print data=allvarout noobs; by member; pageby member; title "Variables in #BYVAL(member) data set"; run; ODS EXCEL CLOSE;

16 View output for SASHELP library

17 SASHELP library varies based on products installed
185 data sets in SASHELP in Census Bureau’s virtual desktop infrastructure environment 86 data sets in SASHELP in SAS University Edition

18 Conclusions ODS Excel destination is easy to use
Produces native Excel output Can quickly document all variables in SAS library

19 Questions? suzanne.marie.dorinski@census.gov
There is a page for this talk on the sasCommunity.org wiki. The page will be updated with the SESUG paper and slides. The page already contains the sample code and Excel output. The QR code on the slide takes you to the list of the papers I’ve presented, which has a link for this paper.


Download ppt "Beautiful PROC CONTENTS Output Using the ODS Excel Destination"

Similar presentations


Ads by Google