Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004.

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

Copyright © 2006, SAS Institute Inc. All rights reserved. Think FAST! Use Memory Tables (Hashing) for Faster Merging Gregg P. Snell Data Savant Consulting.
Axio Research E-Compare A Tool for Data Review Bill Coar.
The SAS ® System Additional Information on Statistical Analysis Programming.
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
SAS Programming Techniques for Decoding Variables on the Database Level By Chris Speck PAREXEL International RTSUG – Wednesday, March 23, 2011.
MASUG December 5, Agenda Announcements Announcements Tips & Tricks Tips & Tricks Presentation: Presentation: Working Smarter, Not Harder with DDE:
SAS Output Delivery System. Find heart in the sashelp library Double click.
Basic And Advanced SAS Programming
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.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Creating SAS® Data Sets
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 Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
© OCS Consulting The flexible extension to your IT team 1 Jim Groeneveld, OCS Consulting, ´s Hertogenbosch, Netherlands. PhUSE 2011 Comparing dataset metadata.
Writing Maintainable Code with ‘Style’ Allan Page Senior Marketing Analyst Canadian Tire Bank.
Introduction to the LOGPARSE Macro GASUG Atlanta, GA July 18 th, 2007.
Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin.
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
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.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
1 PhUSE 2011 Missing Values in SAS Magnus Mengelbier Director.
Copyright © 2011, SAS Institute Inc. All rights reserved. Using the SAS ® Clinical Standards Toolkit 1.4 to work with the CDISC ODM model Lex Jansen SAS.
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.
I OWA S TATE U NIVERSITY Department of Animal Science Getting Your Data Into SAS (Chapter 2 in the Little SAS Book) Animal Science 500 Lecture No. 3 September.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to Using the Data Step Hash Object with Large Data Sets Richard Allen Peak Stat.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
1 Efficient SAS Coding with Proc SQL When Proc SQL is Easier than Traditional SAS Approaches Mike Atkinson, May 4, 2005.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
Code Generation. 2 Overview of presentation Goal Background Dynamic SQL Method Examples.
© OCS Biometric Support 1 APPEND, EXECUTE and MACRO Jim Groeneveld, OCS Biometric Support, ‘s Hertogenbosch, Netherlands. PhUSE 2010 – CC05 PhUSE 2010.
A SAS User's Guide to Storage Management Allan Page Senior Marketing Analyst Canadian Tire Financial Services.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
YET ANOTHER TIPS, TRICKS, TRAPS, TECHNIQUES PRESENTATION: A Random Selection of What I Learned From 15+ Years of SAS Programming John Pirnat Kaiser Permanente.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
SHRUG, F EB 2013: N ETWORKING EXERCISE Many Ways to Solve a SAS Problem.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
Do not put content on the brand signature area NOBS for Noobs David B. Horvath, CCP, MS PhilaSUG Winter 2015 Meeting NOBS for Noobs.
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.
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Build your Metadata with PROC CONTENTS and ODS OUTPUT Louise S. Hadden Abt Associates Inc.
Better Metadata Through SAS® II: %SYSFUNC, PROC DATASETS, and Dictionary Tables.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Beautiful PROC CONTENTS Output Using the ODS Excel Destination Suzanne Dorinski SESUG 2015 Disclaimer: Any views expressed are those of the author and.
A MORE COMPLETE ODS REPORT. What we’re going to talk about…  Creating a title page  Creating an introduction page  Creating long-form text descriptions.
SAS Programming Introduction to SAS.
Chapter 1: Introduction to SAS
Instructor: Raul Cruz-Cano
PROC DOC III: Self-generating Codebooks Using SAS®
Creating the Example Data
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
How to Create Data Driven Lists
Hunter Glanz & Josh Horstman
Never Cut and Paste Again
Frank DiIorio CodeCrafters, Inc. Philadelphia PA
Presentation transcript:

Copyright © 2004, SAS Institute Inc. All rights reserved. SASHELP Datasets A real life example Barb Crowther SAS Consultant October 22, 2004

Copyright © 2004, SAS Institute Inc. All rights reserved. 2 Situation  The Canadian government requires all financial institutions to report suspicious financial transactions, including: Cash Money Orders Casino Chips Real Estate ….

Copyright © 2004, SAS Institute Inc. All rights reserved. 3 Situation – Data  The data is extracted from many different applications and saved to a flat file as a ‘report’.  Excluding the header and subheader, there were 9 different parts for each report  Data formatting was very specific and varied from part to part  The number of fields varied from 4 to 35,  Field lengths varied between 1 and 400  The part lengths varied between 139 and 507 characters.

Copyright © 2004, SAS Institute Inc. All rights reserved. 4 Types of Required Information ……

Copyright © 2004, SAS Institute Inc. All rights reserved. 5 The first kicker  Not all reports needed all parts.  Some parts were always required, others only some of the time.  Which parts were included was dependant on the data.  But if the part was required, it had to be perfect!!!

Copyright © 2004, SAS Institute Inc. All rights reserved. 6 The second kicker  The users wanted to be able to edit each part before it was sent to the government – but because of the tool they used, they could not insert (or delete) a missing part.  So even all the fields were missing from the source data, the part had to be included

Copyright © 2004, SAS Institute Inc. All rights reserved. 7 So……….  The application had to insert each required part  The only information I would get is a sequence number.

Copyright © 2004, SAS Institute Inc. All rights reserved. 8 Attempt #1 – Hard code the data step For each of the nine parts….. …. For each of the 10 to 35 fields per part…. …I could write a “length variable ($) n;” statement. Oh, and by the way, did I tell you that the government regularly changes part content?

Copyright © 2004, SAS Institute Inc. All rights reserved. 9 Attempt #2 – Investigate system options Options obs=0; Data parta1; set input.parta1; Run; Options obs=max; The problem with this code is the output dataset has no observations and I needed one, even if there was no data.

Copyright © 2004, SAS Institute Inc. All rights reserved. 10 Attempt #3 – Look at SASHELP.datasets  The SASHELP datasets contain information about the current SAS session including all the members of all the libraries (SASHELP.VMEMBER) all the columns of each member (SASHELP.VCOLUMN)

Copyright © 2004, SAS Institute Inc. All rights reserved. 11 VCOLUMN Contents Variable NameVariable LabelCreate Date … FormatColumn Format InformatColumn Informat LabelColumn Label LengthColumn Length LibnameLibrary Name MemnameMember Name TypeColumn Type …

Copyright © 2004, SAS Institute Inc. All rights reserved. 12 Accessing V* Tables  Accessing the V* Tables can be done using PROC, SQL, or Data statements proc print data=sashelp.vtable; where libname='WORK'; run; proc sql; create view work.options as select * from dictionary.options;

Copyright © 2004, SAS Institute Inc. All rights reserved. 13 So how does this help me?  Step 1: Get a list of all the variables (and their attributes) required for the “empty dataset”.  Step 2: Move all that information into macro variables  Step 3: Create a dataset template  Step 4: Create the empty dataset.

Copyright © 2004, SAS Institute Inc. All rights reserved. 14 Step 1: Variables and their attributes proc sql noprint; create table &table._vars as select name, type, format, length, label from sashelp.vcolumns where upcase(libname)=upcase("&inset") and upcase(memname) = upcase("&table") ; quit; For this example, our inset will be Work and our table Txns.

Copyright © 2004, SAS Institute Inc. All rights reserved. 15 Step 1: Work.Txns_vars VCOLUMNS Output NameTypeFormatLengthLabel Tran_dateChar8 Tran_Post_DateChar8 Tran_CurrencyChar$3.003Currency_code Tran_timeChar4 Tran_AmountNum8 Teller_idChar$15 …

Copyright © 2004, SAS Institute Inc. All rights reserved. 16 Step 2: Create macro variables using Txns_vars from Step 1 data _null_; set &table._vars end=eof; call symput('var'||left(put(_n_,3.)),name); if format ne ' ' then call symput('fmt'||left(put(_n_,3.)),format); else if upcase(type) = 'CHAR' then call symput('fmt'||left(put(_n_,3.)),'$'|| put(length,3.)||'.'); if label ne ' ' then call symput('label'||left(put(_n_,3.)),label); if eof then call symput('var_cnt',left(put(_n_,3.))) ; run;

Copyright © 2004, SAS Institute Inc. All rights reserved. 17 Step 2: Macro Output from the SASLOG

Copyright © 2004, SAS Institute Inc. All rights reserved. 18 Step 3: Create the dataset template Work.Txn_tpl using the Step 2 macro variables %let i = 1; data &table._tpl; %do i=1 %to &var_cnt; attrib &&var&i format= &&fmt&i label = "&&label&i"; %end;

Copyright © 2004, SAS Institute Inc. All rights reserved. 19 Step 3: Create the dataset template generated code to create Work.Txn_tpl Value of iGenerated Code 1Attrib transaction_key format = 20. label = ‘transaction_key”; 2Attrib transaction currency format = $3. label=‘Currency Code’; …

Copyright © 2004, SAS Institute Inc. All rights reserved. 20 Step 3: Create a dataset template Get a list of the required variables %global &table._var_list; proc sql noprint; select distinct name into :&table._var_list separated by ' ' from &table._vars ; quit; Results in a macro variable called txn_var_list with a value of TRANSACTION_KEY TRAN_CURRENCY …

Copyright © 2004, SAS Institute Inc. All rights reserved. 21 So where are we?  We have a report with a known sequence number, but no data  We know what variables are required &txn_var_list  We know the variables’ attributes &&var&i format= &&fmt&i label = "&&label&i";

Copyright © 2004, SAS Institute Inc. All rights reserved. 22 Step 4: Create the empty dataset

Copyright © 2004, SAS Institute Inc. All rights reserved. 23 Step 4: Code to generate the dataset data &table._miss_data; retain &&&table._var_list; set result (keep=seq_num); if _n_ = 1 then set &table._tpl(drop=seq_num); run;

Copyright © 2004, SAS Institute Inc. All rights reserved. 24 Thoughts…  Writing the macros took longer than hard coding the attribute statements.  But, if there are any future changes, I won’t have to do very much (if any).  The macros can be used in other applications…

Copyright © 2004, SAS Institute Inc. All rights reserved. 25 Suggested readings  The SASHELP Library: It Really Does Help You Manage Data by Melinda Thielbar p.htmlhttp://support.sas.com/sassamples/bitsandbytes/sashel p.html  You Could Look It Up: An Introduction to SASHELP Dictionary Tables by Michael Davis You Could Look It Up: An Introduction to SASHELP Dictionary Tables

Copyright © 2004, SAS Institute Inc. All rights reserved. 26 Copyright © 2004, SAS Institute Inc. All rights reserved. 26