Ottawa Area SAS Users Society

Slides:



Advertisements
Similar presentations
Oracle PL/SQL IV Exceptions Packages.
Advertisements

VBA Modules, Functions, Variables, and Constants
Introduction to SQL Session 1 Retrieving Data From a Single Table.
School of Computer ScienceG53FSP Formal Specification1 Dr. Rong Qu Introduction to Formal Specification
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Chapter 6 SAS ® OLAP Cube Studio. Section 6.1 SAS OLAP Cube Studio Architecture.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
Lecture 16 Pass by value vs. pass by reference (Still) Appearances are often deceiving Aesop, Fables.
Presented by : Sébastien Lauzon (Finance Canada).
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
 2004 Prentice Hall Business Publishing, Accounting Information Systems, 9/e, by Bodnar/Hopwood 10 – 1 Systems Planning and Analysis Chapter 10.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
CS 0401 Debugging Hints and Programming Quirks for Java by John C. Ramirez University of Pittsburgh.
Chapter 7: Macros in SAS  Macros provide for more flexible programming in SAS  Macros make SAS more “object-oriented”, like R 1 © Fall 2011 John Grego.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
Module 9: Operator overloading #1 2000/01Scientific Computing in OOCourse code 3C59 Module 9: Operator Overloading In this module we will cover Overloading.
SAS ® Global Forum 2014 March Washington, DC.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Notes on SQL. SQL Programming Employers increasingly tell us that they look for 3 things on a resume: SAS, R and SQL. In these notes you will learn: 1.What.
“Come out of the desert of ignorance to the OASUS of knowledge” Put Data in the Driver's Seat Andrew Clapson, MD Financial Management.
Certification of Reusable Software Artifacts
Information Systems Development
: PROC SORT: C O O P R R S T Jayson Shurgold, Health Canada
Session 1 Retrieving Data From a Single Table
Game Design For Development
Development Environment
Chapter 2: The Visual Studio .NET Development Environment
Dynamic SQL Writing Efficient Queries on the Fly
Greg Steffens Noumena Solutions
Systems Planning and Analysis
Learning to Program D is for Digital.
Programming Standards and Practices
7 - Programming 7P, Q, R - Testing.
-by Nisarg Vasavada (Compiled*)
Data types and variables
Topics Introduction to Repetition Structures
Microsoft Access Illustrated
Information Systems Development
By Don Henderson PhilaSUG, June 18, 2018
Conditional Processing
Fall 2017 Questions and Answers (Q&A)
Chapter 7: Macros in SAS Macros provide for more flexible programming in SAS Macros make SAS more “object-oriented”, like R Not a strong suit of text ©
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Coding Concepts (Sub- Programs)
Macro Variable’s scope
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Using JDeveloper.
Defining and Calling a Macro
Dynamic Scoping Lazy Evaluation
Global and Local Symbol Tables
3 Iterative Processing.
Building Java Programs
Create – Performance Task
Lab 3 and HRP259 Lab and Combining (with SQL)
Lecture 5: Functions and Parameters
Examining Variables on Flow Paths
Chapter 8 Advanced SQL.
(Computer fundamental Lab)
Tonga Institute of Higher Education IT 141: Information Systems
Data Structures & Algorithms
Topics Introduction to Repetition Structures
NETWORK PROGRAMMING CNET 441
Tonga Institute of Higher Education IT 141: Information Systems
Course Overview PART I: overview material PART II: inside a compiler
Prof. Arfaoui. COM390 Chapter 7
CISC101 Reminders Assignment 3 due today.
Software Development Techniques
Classes and Objects Object Creation
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Ottawa Area SAS Users Society A Topic Proposed: DOSUBL Presented by Jayson Shurgold of Health Canada Ottawa Area SAS Users Society May 25th, 2017

Disclaimer The views expressed in this presentation are the personal views of the presenting staff and do not necessarily represent the views of Health Canada or the Government of Canada. The presentation is provided for general information purposes intended only as an academic resource and does not constitute professional advice. Information has been summarized and paraphrased for presentation purposes and the examples are theoretical and have been provided for illustration purposes only.

About me: Opportunistic SAS user since 9.1 | 2005 Professionally applied since 2007 Vancouver SAS User Group (VANSUG) | 2013, 2014, 2015 Ottawa Area SAS Users Society (OASUS) | 2016, 2017 SAS all expenses paid invitation to Global Forum | 2018? No previous experience in DOSUBL until a few days ago

Fundamentals

Fundamentals To most beginners, SAS is presented as having two coding environments: DATA and PROC. Each of these environments has its own use: DATA: Typically manipulations, merges, and conditional logic PROC: Packaged procedures (sorting/reporting) DATA PROC DATA – create datasets PROC – process datasets

Fundamentals The DATA and PROC coding environments are distinct tools, used in conjunction with each other to achieve a result. Many programmers, myself included, navigate analytical challenges by chaining these tools one after the other. Example 1: Descriptive Analysis Example 2: Data Merge DATA PROC PROC DATA

Fundamentals However, it is possible to run PROC environments inside of a DATA environment, and vise versa. Example 1: PROC inside DATA Example 2: Data inside PROC DATA PROC PROC DATA

DOSUBL - Code within a Code

DOSUBL - Code within a Code Inception is a movie released in 2010 that follows a character named Cobb, who is a thief who can steal secrets from people as they sleep via their subconscious thoughts. Cobb is hired by a major corporation, not to steal secrets, but to plant an idea into the (soon to be) CEO of a competing corporation via his subconscious – something never before done. This involves creating dreams within dreams to achieve a “real-world” impact. (not Cobb’s totem)

DOSUBL - Code within a Code DOSUBL is a function that submits and runs SAS code to completion inside an already running DATA step (“data-ception”), and is particularly useful when working with macro variables. Example 1 – Without DOSUBL Example 2 – With DOSUBL DATA DATA DATA DATA

DOSUBL Syntax Syntax: dosubl (‘argument’); data _null_; a = dosubl( ‘data x; y=1; run; %let abc=1;’); b = symget(‘abc’); put b=; run; Data New; Set x; Run; Result:

DOSUBL Syntax Syntax: Dosubl (‘argument’); data _null_; a = dosubl( ‘data x; y=1; run; %let abc=1;’); b = symget(‘abc’); put b=; run; Data New; Set x; Run; Result: b=1 | Data step OK Creation of new Dataset Creation of macro variable

DOSUBL Example: Count and display the number of Obs and Vars for Database TEST in a single DATA step. Data _null_; a = dosubl(‘ proc sql; select count (i) into :n from TEST; select (distinct i) into :dist from TEST; quit; ‘); Nobs = input(symget(‘n’),best.); Nvars = input(symget(‘dist’),best.); Put n= dist=; Run;

DOSUBL Pitfalls

DOSUBL Pitfalls: %Global vs %Local Code in a Code in a Code The DOSUBL function has bugs when working with local and global macro variables that share the same name Code in a Code in a Code A DOSUBL code invoked by a prior DOSUBL code can cause the macro variables to become unreliable in a semi-predicable manner SAS Government Grid (?) Could only successfully implement a DOSUBL function when specifying %global

DOSUBL Pitfalls: DOSUBL As written by Lorne Klassen

DOSUBL Pitfalls: %Global vs %Local Code in a Code in a Code The DOSUBL function has bugs when working with local and global macro variables that share the same name Code in a Code in a Code A DOSUBL code invoked by a prior DOSUBL code can cause the macro variables to become unreliable in a semi-predicable manner SAS Government Grid (?) Could only successfully implement a DOSUBL function when specifying %global

DOSUBL Pitfalls: But set _n_ to 1000, and the macro variables start toggling back and forth in their odd pattern.  The pattern seems to be this:  The value of the macro variable appears to toggle back to a prior state upon the completion of a data step.  Note that even outside the Test_Macro, the value toggles yet again after the completion of the primary DATA step

DOSUBL Pitfalls: %Global vs %Local Code in a Code in a Code The DOSUBL function has bugs when working with local and global macro variables that share the same name Code in a Code in a Code A DOSUBL code invoked by a prior DOSUBL code can cause the macro variables to become unreliable in a semi-predicable manner SAS Government Grid Conflicts (?) Could only successfully implement a DOSUBL function when specifying %global

DOSUBL Pitfalls: DOSUBL As written by Rick Langston, run on GRID data _null_; a = dosubl(‘data x; y=1; run; %let abc=1;’); b = symget(‘abc’); put b=; run; Data New; Set x; Run; Result: b= _ERROR_ | Data step OK DOSUBL Amended, run on GRID data _null_; a = dosubl(‘data x; y=1; run; %global; %let abc=1;’); b = symget(‘abc’); put b=; run; Data New; Set x; Run; Result: b=1 | Data step OK

DOSUBL Summary: A programming method that allows you to run a code within a code Allows the user to: Invoke results from a PROC step in a single DATA step Invoke results from a DATA step in a single PROC step Define and call macro variables in a single DATA / PROC step Efficiently write dynamic code that updates itself Output results at different stages of processing Be cautious of the pitfalls associated with this function

Questions? References: https://communities.sas.com/t5/SAS-Enterprise-Guide/DOSUBL-Bug/td-p/254668 http://support.sas.com/resources/papers/proceedings12/227-2012.pdf https://support.sas.com/resources/papers/proceedings13/032-2013.pdf