Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.

Slides:



Advertisements
Similar presentations
When Good Looks Arent Enough Lisa Eckler. When Good Looks Arent Enough.
Advertisements

Planting Your Rows: Using SAS ® Formats to Make the Generation of Zero-Filled Rows in Tables Less Thorny Kathy Hardis Fraeman HASUG Q
Delivering Multi-Sheet Excel Reports from a Parameterized Stored Process TU02 Richard DeVenezia, Independent Consultant Harry Droogendyk, Stratia Consulting.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
Axio Research E-Compare A Tool for Data Review Bill Coar.
Guide to extract/download multiple databases from Mainframe Tapes to PC using SAS PC Fereydoun J. Foroudian Blue Cross of California SAS is a registered.
MASUG December 5, Agenda Announcements Announcements Tips & Tricks Tips & Tricks Presentation: Presentation: Working Smarter, Not Harder with DDE:
Let SAS Do the Coding for You! Robert Williams Business Info Analyst Sr. WellPoint Inc.
PROC_CODEBOOK: An Automated, General Purpose Codebook Generator
Chapter 18: Modifying SAS Data Sets and Tracking Changes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
FORMAT FESTIVAL AN INTRODUCTION TO SAS® FORMATS AND INFORMATS By David Maddox.
Copyright © 2010, SAS Institute Inc. All rights reserved. Define.xml - Tips and Techniques for Creating CRT - DDS Julie Maddox Mark Lambrecht SAS Institute.
Copyright © 2010, Meta-Xceed, Inc. All rights reserved. BI Flash and all other Meta-Xceed Inc. product or service names are registered trademarks or trademarks.
SAS SQL SAS Seminar Series
SAS Macros ® 101 How I learned to stop worrying and love macros Alex Chaplin BCS USA Section.
A Concise Display of Multiple Response Items Patrick Thornton.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Niraj J. Pandya, Element Technologies Inc., NJ.  Summarize all possible combinations of class level variables even if few categories are altogether missing.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
Report Management Using the ODS DOCUMENT Destination and Report Metadata Brit Harvey February 2010.
My ODS: Real-World Uses of Modifying Table Templates Steve James Centers for Disease Control and Prevention Atlanta, Ga.
Multiple Uses for a Simple SQL Procedure Rebecca Larsen University of South Florida.
%rtf2data: A utility macro to convert RTF Table to SAS® dataset
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
PROC SQL: Tips and Translations for Data Step Users By: Gail Jorgensen Susan Marcella.
Essential ODS PDF Patrick Thornton.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
1 Back Up with Each Submit One approach for keeping a dynamic back up copy of your current work.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
5/30/2010 SAS Macro Language Group 6 Pradnya Nimkar, Li Lin, Linsong Zhang & Loc Tran.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
Copyright © 2004, SAS Institute Inc. All rights reserved. SAS Stored Processes An analyst’s perspective Sylvain Tremblay SAS Canada 24 February 2006.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
Copyright © 2005, SAS Institute Inc. All rights reserved. SAS is a registered trademark or trademark of SAS Institute Inc. in the USA and other countries.
Copyright © 2010, SAS Institute Inc. All rights reserved. SAS ® Using the SAS Grid.
Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004.
Customize SAS Output Using ODS Joan Dong. The Output Delivery System (ODS) gives you greater flexibility in generating, storing, and reproducing SAS procedure.
Do not put content on the brand signature area NOBS for Noobs David B. Horvath, CCP, MS PhilaSUG Winter 2015 Meeting NOBS for Noobs.
PROC CATALOG The Wish Book SAS® Procedure. 2 PROC CATALOG, the Wish Book SAS® Procedure Louise S. Hadden Abt Associates Inc. PROC CATALOG, the Wish Book.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
Using SAS Stored Processes and the SAS Portal for Delivering Statistics to Drug Discovery Volker Harm PhUSE/PSI One-day Event 2009, Marlow.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Copyright © SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
Beautiful PROC CONTENTS Output Using the ODS Excel Destination Suzanne Dorinski SESUG 2015 Disclaimer: Any views expressed are those of the author and.
Tips for Mastering Relational Databases Using SAS/ACCESS®
Poster Title Author #1 name, ABC Corporation, City, Country Author #2 name, ABC Corporation, City, Country Abstract A brief abstract at the beginning summarizes.
A brief introduction to the topic
Poster Title Author #1 name, ABC Corporation, City, Country Author #2 name, ABC Corporation, City, Country Abstract A brief abstract at the beginning summarizes.
Instructor: Raul Cruz-Cano
Fall 2017 Questions and Answers (Q&A)
PROC DOC III: Self-generating Codebooks Using SAS®
Beautiful PROC CONTENTS Output Using the ODS Excel Destination
%SUBMIT R A SAS® Macro to Interface SAS and R
How to Create Data Driven Lists
Lisa Mendez, PhD & Andrew Kuligowski
Dictionary Tables and Views, obtain information about SAS files
Never Cut and Paste Again
A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets. Venkata N Madhira Senior Statistical.
Automate Repetitive Programming Tasks: Effective SAS® Code Generators
Making Remote Processing Less Remote
Instructor: Raul Cruz 9/4/13
Tips and Tricks for Using Macros to Automate SAS Reporting.
Efficient Use of Disk Space in SAS® Application Programs
Frank DiIorio CodeCrafters, Inc. Philadelphia PA
Presentation transcript:

Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables

2 Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Introduction Resources within SAS® to Obtain Metadata SAS® provides a wealth of resources for users to create useful, attractive metadata tables, including PROC CONTENTS listing output (to ODS destinations), the PROC CONTENTS OUT= SAS data set, and PROC CONTENTS ODS Output Objects. This paper and presentation explore some additional and less well-known resources to obtain metadata on SAS sessions such as %SYSFUNC, PROC DATASETS, and Dictionary Tables. All these options in conjunction with the use of SAS ODS tagsets, datasets and procedures enable the creation of user friendly documentation and programming tools. Each new SAS session opens the door to a wealth of valuable metadata on data sets, SAS catalogs, directories, users, systems, SAS versions, and even the session itself. Follow me through the wormhole… %SYSFUNC (or %QSYSFUNC) is a macro function that allows you to access SAS language functions regardless of the system environment you are operating in. For example, %IF %SYSFUNC(EXIST(infi) ) %THEN %DO;... %END; sets up conditional processing based on infi’s existence. met·a·da·ta ˈ medə ˌ dādə, ˈ medə ˌ dadə/ noun a set of data that describes and gives information about other data. PROC DATASETS does all that PROC CONTENTS does, and much, much more. For example, PROC DATASETS LIBRARY=YOURLIB NOLIST NODETAILS; CONTENTS DATA=_ALL_ OUT=YOURDS NOPRINT NODETAILS DIRECTORY; provides a single contents listing of all files in a library. SAS dictionary tables and SASHELP views allow access to all the information SAS collects about a SAS session. For example, PROC SQL; SELECT NAME, MEMNAME, TYPE, LENGTH FROM DICTIONARY.COLUMNS WHERE LIBNAME=‘YOURLIB’ AND NAME CONTAINS ‘ID’; QUIT; lists all datasets in a library that have a variable called ID.

3 Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. %SYSFUNC and PROC DATASETS Although %SYSFUNC, PROC DATASETS, Dictionary Tables, SASHELP Views and V functions are very powerful, many faceted tools about which many papers are written, it is the intent of this paper to describe how to get metadata for data dictionaries and codebooks, and to facilitate the processing of data – in other words, how to get to know thy data. It is a credit to SAS that we have so many options. It is also worth noting that all these options draw on the same SAS metadata – all the information is at our fingertips any time we invoke a SAS session, disappearing when we exit a SAS session. Selected SAS® functions that can be used with %SYSFUNC: Verify existence of a file; open a file; get information about a file, delete a file, close a file, read a host- specific option. Example 1: Find the number of observations in a data set Example 1: Find the number of observations in a data set Example 2: Create an output data set of the contents of many datasets Example 2: Create an output data set of the contents of many datasets /* find the number of observations in a data set */ %LET dsexist=%SYSFUNC(EXIST(sashelp.zipcode)); % LET sasdsname=sashelp.zipcode; % LET dsid=%SYSFUNC (OPEN(&sasdsname)); % LET numobs=%SYSFUNC(ATTRN(&dsid,NOBS)); % LET rc=%SYSFUNC (CLOSE(&dsid)); /* put the number of observations in the log */ %PUT The # of observations in &sasdsname is &numobs; In the log: The # of observations in sashelp.zipcode is /* generate a contents listing of all data sets in SASHELP */ PROC DATASETS LIBRARY=SASHELP NOLIST; CONTENTS DATA=_ALL_ OUT=LIB.SASHELP_DS_METADATA (KEEP=LIBNAME MEMNAME NAME TYPE LENGTH LABEL FORMAT NOBS COMPRESS SORTED IDXUSAGE CRDATE MODATE) NOPRINT DIRECTORY; RUN; /* Add a data set label */ PROC DATASETS LIBRARY=LIB; MODIFY SASHELP_DS_METADATA (LABEL="Metadata for all SAS data sets in SASHELP"); CONTENTS DATA=SASHELP_DS_METADATA; RUN: QUIT; Snippet of PROC DATASETS CONTENTS listing Snippet of test print of created metadata data set

4 Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. DICTIONARY TABLES / SASHELP VIEWS / “V” FUNCTIONS SAS® provides a lot of useful metadata, but it is up to us to do our part. We can greatly enhance our data dictionaries and codebooks by using SAS tools to describe our data, our files, our SAS catalogs and entries, our systems, and users. Example 2 shows how to use PROC DATASETS to modify a data set by adding a descriptive label. You can use %SYSFUNC to add system and user information, processing dates, program names, etc. to labels and descriptions. You can use PROC CATALOG to add information to SAS catalog entries – and all this can be reported on. Example 3: Find a variable in multiple data sets Example 3: Find a variable in multiple data sets Example 4: Create a codebook data set from SASHELP views Example 4: Create a codebook data set from SASHELP views Example 5: Using V functions to obtain metadata Example 5: Using V functions to obtain metadata PROC SQL; CREATE TABLE LIB.SASHELP_ZIPCODE_CDBK AS SELECT NAME, TYPE, LENGTH, FORMAT, VARNUM, IDXUSAGE, SORTEDBY, LABEL FROM SASHELP.VCOLUMN WHERE LIBNAME='SASHELP' AND MEMNAME='ZIPCODE'; QUIT; PROC PRINT DATA=LIB.SASHELP_ZIPCODE_CDBK (OBS=10) NOOBS; RUN; PROC SQL; TITLE1 'ALL DATA SETS IN SASHELP WITH A VARIABLE NAMED ZIP'; SELECT LIBNAME, MEMNAME, NAME FROM DICTIONARY.COLUMNS WHERE NAME='ZIP' and libname='SASHELP'; QUIT; DATA dateformattest; LENGTH srvy_dt_type... $ 1 srvy_dt_fmt...$ 32; SET defs.alltexts_indx ; IF _n_=1; srvy_dt_type=VTYPE(srvy_dt);... srvy_dt_fmt=VFORMAT(srvy_dt);... RUN; Output from PROC SQL Output from PROC PRINT – Example 4 Output from PROC PRINT – Example 5

5 Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Louise S. Hadden Abt Associates Inc. Conclusion References Acknowledgements 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. Your comments and questions are valued and encouraged. Contact the author at: Name: Louise Hadden Carey, Helen and Carey, Ginger, “Tips and Techniques for the SAS Programmer!” Proceedings of SAS Global Forum Crawford, Peter, “A Day in the Life of Data – Part 3.” Proceedings of SAS Global Forum Fraeman, Kathy Hardis, “Get into the Groove with %SYSFUNC: Generalizing SAS® Macros with Conditionally Executed Code.” Proceedings of NESUG Hadden, Louise, “Build your Metadata with PROC CONTENTS and ODS OUTPUT”, Proceedings of SAS Global Forum Huang, Chao, “Top 10 SQL Tricks in SAS®.” Proceedings of SAS Global Forum Karafa, Matthew T., “Macro Coding Tips and Tricks to Avoid “PEBCAK” Errors.” Proceedings of SAS Global Forum Kuligowski, Andrew T. and Shankar, Charu, “Know Thy Data: Techniques for Data Exploration.” Proceedings of SAS Global Forum Lafler, Kirk Paul, “Powerful and Hard-to-find PROC SQL Features.” Proceedings of SAS Global Forum Murphy, William C., “What’s in a SAS® Variable? Get Answers with a V!” Proceedings of SAS Global Forum Raithel, Michael A., “PROC DATASETS: the Swiss Army Knife of SAS® Procedures.” Proceedings of SAS Global Forum Thornton, Patrick, “SAS® DICTIONARY: Step by Step.” Proceedings of SAS Global Forum Zhang, Jingxian, “Techniques for Generating Dynamic Code from SAS® Dictionary Tables.” Proceedings of SAS Global Forum If you are looking to find SAS metadata, there’s more than one way to skin a cat! Take advantage of the master procedure PROC DATASETS (as well as PROC CONTENTS), SAS Dictionary Tables and SASHELP.VIEWS, and information gleaned from using the powerful %SYSFUNC to create user documentation, generate SAS code, perform conditional processing and GET INPUT! The author gratefully acknowledges the helpful work of Kathy Fraeman, Michael Raithel, Patrick Thornton and Kirk Paul Lafler, among others.