Presentation is loading. Please wait.

Presentation is loading. Please wait.

Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.

Similar presentations


Presentation on theme: "Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc."— Presentation transcript:

1 Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.

2 Definitions met·a·da·ta ˈmetəˌdatə,-ˌdātə/ noun 1.a set of data that describes and gives information about other data

3 Definitions ODS Output Objects: Most SAS procedures generate ODS objects behind the scenes. SAS uses these objects in conjunction with style templates that have custom “buckets” for certain types of output to produce the output we see in all destinations.

4 Definitions The task at hand: create an Excel Workbook with data set information on multiple data sets in multiple worksheets, all within your SAS program, with no user intervention. Oh, and could you just add an index of the files reported on as the first worksheet?

5 Choices 1.Use ODS to output PROC CONTENTS OUTPUT 2.Use PROC CONTENTS OUT= and output the result to ODS 3.Use ODS Output Objects and output to ODS There are pros and cons to each approach.

6 Using ODS Objects 4 easy pieces Identify / locate your ODS output object(s) using ODS TRACE. Output your ODS output object(s) and view them by using basic SAS procedures. Manipulate your ODS output object(s) using SAS. Report on your final data set to ODS.

7 ODS TRACE ODS TRACE ON / LABEL; PROC CONTENTS DATA=LIB.YOURDATA; RUN; ODS TRACE OFF;

8 Output ODS OUTPUT ATTRIBUTES=atr VARIABLES=var SORTEDBY=sortedby&infi.; PROC CONTENTS DATA=&inlib..&infi ; RUN; ODS OUTPUT CLOSE;

9 Analyze

10 Create Variable Listing File PROC SORT DATA=var; BY num; RUN; DATA &infi; SET var (DROP=member pos); RENAME num=varnum variable=name len=length; RUN;

11 Create Index Information We need to build an index line for each file. In order to do this, we access different records and variables from the atr (attribute) and a record from the sortedby&infi (sortedby) file. This presents a challenge as sortedby&infi is not created for an unsorted file.

12 Create Index Information Within the overall macro, conditionally execute data steps: %IF %SYSFUNC(EXIST(sortedby&infi)) %THEN %DO;... If the file exists then do a data step transforming it... %END; %ELSE %DO;... If it doesn’t exist, then do a data step creating it... %END;

13 Create Index Information Perform a series of data steps which grab particular variables / records and output a single record file. DATA sorted (KEEP=sorted); SET atr (WHERE=(label1='Data Set Type')); sorted=cvalue2; RUN;...

14 Create Index Information The single record files for each data set are merged together to create an index file. DATA &headfi; MERGE member memlabel nvars sorted sortvar; RUN; Note that because each header file only has a single record and no common variables, no merge by variable is needed or used in this case.

15 Report on Designer Data Set(s) The code I’ve shown you glimpses of runs inside a macro, and seven variable level data sets and an index data set have been created. Now, it’s time to create our Excel Workbook, using ODS TAGSETS.EXCELXP and DDE – All without touching your keyboard.

16 TAGSETS.EXCELXP ODS TAGSETS.EXCELXP FILE=".\file.xml"; ODS TAGSETS.EXCELXP OPTIONS (ABSOLUTE_COLUMN_WIDTH ="32,90,10,10,10,60“ SHEET_INTERVAL="Table“ SHEET_NAME="Index" ); PROC PRINT DATA=index NOOBS; RUN;... ODS TAGSETS.EXCELXP CLOSE; QUIT;

17 EXCELXP -> DDE -> XLSX Using DDE (Dynamic Data Exchange), we open Excel. Once Excel is open, we then open the XML file created by ODS TAGSETS.EXCELXP, and “save as” an XLSX file. To save space, and avoid confusion, we then delete the XML file. You can also issue other DDE commands to Excel to do things like freeze rows and columns, etc. in the same manner. filename cmds dde 'excel|system';

18 The Metadata Workbook

19 CONCLUSION Using the techniques demonstrated in this presentation, you can easily produce metadata workbooks for your project. These techniques can also be used in conjunction with other procedures to produce designer data sets, etc. The possibilities are endless. Could THIS program be improved? Absolutely! We could add formatting to our output workbook with TAGATTR, and streamline the code, etc. Let me know how you make this your own!

20 Contact Information Your comments and questions are valued and encouraged. Contact the author at: Louise Hadden louise_hadden@abtassoc.com Code samples are available upon request. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies.


Download ppt "Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc."

Similar presentations


Ads by Google