Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ottawa Area SAS Users Society

Similar presentations


Presentation on theme: "Ottawa Area SAS Users Society"— Presentation transcript:

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

2 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.

3 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

4 Fundamentals

5 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

6 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

7 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

8 DOSUBL - Code within a Code

9 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)

10 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

11 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:

12 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

13 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;

14 DOSUBL Pitfalls

15 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

16 DOSUBL Pitfalls: DOSUBL As written by Lorne Klassen

17 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

18 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

19 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

20 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

21 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

22 Questions? References:


Download ppt "Ottawa Area SAS Users Society"

Similar presentations


Ads by Google