Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP – Data Step Functions

Slides:



Advertisements
Similar presentations
Copyright © 2013, SAS Institute Inc. All rights reserved. SAS INTELLIGENT ADVERTISING FOR PUBLISHERS NEW BUSINESS INTELLIGENCE FEATURES AND PROCESS OVERVIEW.
Advertisements

1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 4.1 Chapter 4.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 6.1 Chapter 6.
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
Chapter 3 Describing Syntax and Semantics. Copyright © 2007 Addison-Wesley. All rights reserved 3–2.
Copyright © 2006, SAS Institute Inc. All rights reserved. Shortcuts- what you may not know that can save you time! Elizabeth Ceranowski SAS Student Programs.
Hello SAS 9.4: What's New? ChrIs Hemedinger, SAS.
Copyright © 2005, SAS Institute Inc. All rights reserved. Effective Use of SAS/GRAPH® Stored Processes Pat Berryman Senior Software Manager Data Visualization.
by Barb Philipak 2002 Plank Road Publishing, Inc. International Copyright Secured * All Rights Reserved ©
Copyright © 2005, SAS Institute Inc. All rights reserved. SAS Office Integration with the BI Server Jennifer Clegg I-Kong Fu SAS Institute Inc. April 12.
1. Guess the Name of the Product Copyright © Health Education Today, Inc
24-04 Excerpted from Meggs’ History of Graphic Design, Fourth Edition. Copyright 2005, All rights reserved. Published by John Wiley & Sons, Inc.
Waves Copyright© 2015 EducAide Software Inc. All rights reserved.
Section 1.5 Circles Copyright © 2013 Pearson Education, Inc. All rights reserved.
Copyrights apply.
Chapter 24 (4th ed.): Creating Functions
Modeling Constraints with Parametrics
Section 2.5 Graphing Techniques; Transformations
توكيد الذات.
Copyright © 2016 Elsevier Inc. All rights reserved.
Copyright © 2013 Pearson Education, Inc. All rights reserved
Section 9.4 Area of a Triangle
Section 2.5 Graphing Techniques; Transformations
The Inverse Trigonometric Functions (Continued)
Definition Copyright © 2013 Pearson Education, Inc.. All rights reserved.
Copyright © 2012, Elsevier Inc. All rights Reserved.
Section 10.1 Polar Coordinates
Extra Nomenclature Practice Answers
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2012, Elsevier Inc. All rights Reserved.
copyright ALL RIGHTS RESERVED. 4/12/2019 copyright ALL RIGHTS RESERVED.
General Principles for Writing Reaction Mechanisms
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2012, Elsevier Inc. All rights Reserved.
Chapter 28 - Renal Hyperplasia and Hypertrophy
Copyright © 2014, 2000, 1992 Elsevier Inc. All rights reserved.
copyright ALL RIGHTS RESERVED.
Chemistry Ch. 10 Review and worksheets
Copyright © 2012, Elsevier Inc. All rights Reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Section R.2 Algebra Essentials
Modeling Cross-Cutting Relationships with Allocations
Portable Biotechnology
Section 10.5 The Dot Product
FISSION &FUSION New User
Modeling Text-Based Requirements and their Relationship to Design
Modeling Functionality with Use Cases
Customizing SysML for Specific Domains
Unit 4 Review Answers.
Copyright © 2012, Elsevier Inc. All rights Reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
IntroductionMolecular Structure and Reactivity
Copyright © 2013 Elsevier Inc. All rights reserved.
Forms.
Copyright © 2012, Elsevier Inc. All rights Reserved.
Chapter 103 Long-Term Care: The Global Impact
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Chapter 08.
Chapter 64 - Renal Calcium Metabolism
© 2015 Elsevier, Inc. All rights reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2013 Elsevier Inc. All rights reserved.
Copyright © 2012, Elsevier Inc. All rights Reserved.
Chapter 15 Contraception
Copyright © 2013 Elsevier Inc. All rights reserved.
Chapter 20 Assisted Reproductive Technologies
© 2015 Elsevier, Inc. All rights reserved.
Presentation transcript:

Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP – Data Step Functions

Copyright © 2006, SAS Institute Inc. All rights reserved. What is Proc FCMP?  “SAS Function Compiler”  Build functions using DATA step syntax  Store the functions in a data set  Call the functions from the DATA step just as you would any other SAS function  Lots more capabilities, just not covered today

Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP - History  Prior to Version 9.2 – Limited to Product Procs SAS/STAT SAS/ETS SAS/OR  Post 9.2 available – Data step syntax

Copyright © 2006, SAS Institute Inc. All rights reserved. Advantages of Writing Your Own Functions  Function makes a program easier to read, write and modify  Reuse and quality control Test once use many times  Program/function independence

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function - 3 level name Proc FCMP outlib = << Ids where to store sasuser.MySubs.MathFncs; << DS and package function day_date( indate, type $); if type = "DAYS" then wkday = weekday(indate); if type = "YEARS" then wkday = weekday(indate*365); return(wkday); endsub; run;

Copyright © 2006, SAS Institute Inc. All rights reserved. Outlib – 3 Level Name - Package Proc FCMP outlib = sasuser.MySubs.MathFncs;  Library  Dataset  Package – collection of related functions Could be by organized by application or by corporate department

Copyright © 2006, SAS Institute Inc. All rights reserved. Pieces and Parts  4 parts between FUNCTION statement ENDSUB keyword Function name −day_date One or more parameters −( indate, type $); A body of code A RETURN statement −return(wkday);

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function – Statement & Name Proc FCMP outlib = sasuser.MySubs.MathFncs; function day_date( indate, type $); << stmt & name if type = "DAYS" then wkday = weekday(indate); if type = "YEARS" then wkday = weekday(indate*365); return(wkday); endsub; run;

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function – Naming function day_date( indate, type $); << stmt & name  Cannot have a function name that collides with a built-in SAS function name. An error message is generated if an attempt is made.  Name must be unique in the package  2 packages with the same name – qualify name when calling MathFncs.day_date

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function - Arguments function day_date( indate, type $); << arguments function coffee_deal() $ ; << no argument Can have one or more arguments for a function. Specify character arguments by placing a dollar sign ($) after the argument name. In the above example: indate is numeric and type is a character argument

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function – Logic The DAY_DATE function converts a date to a numeric day of the week if type = "DAYS" then wkday = weekday(indate); if type = "YEARS" then wkday = weekday(indate*365);

Copyright © 2006, SAS Institute Inc. All rights reserved. Usage of SAS Function - weekday Proc FCMP outlib = sasuser.MySubs.MathFncs; function day_date( indate, type $); if type = "DAYS" then wkday = weekday(indate); if type = "YEARS" then wkday = weekday(indate*365); return(wkday); endsub; run;

Copyright © 2006, SAS Institute Inc. All rights reserved. Syntax to Create a Function – Return Proc FCMP outlib = sasuser.MySubs.MathFncs; function day_date( indate, type $); if type = "DAYS" then wkday = weekday(indate); if type = "YEARS" then wkday = weekday(indate*365); return(wkday); <<Returns a numeric value endsub; run;

Copyright © 2006, SAS Institute Inc. All rights reserved. Calling the Function Options cmplib = sasuser.mysubs; Data work.usefunc; Numdays = day_date(‘13sep2011’d,”DAYS”); Put numdays=; run; Numdays = 3

Copyright © 2006, SAS Institute Inc. All rights reserved. Options CMPLIB = Options cmplib = sasuser.mysubs; CMPLIB is a SAS option that supports usage with INSERT and APPEND Options insert=(cmplib=sasuser.meFirst) ; Options append=(cmplib=sasuser.meLast);

Copyright © 2006, SAS Institute Inc. All rights reserved.

Nesting and Scope

Copyright © 2006, SAS Institute Inc. All rights reserved. Nesting and Scope DATA Step funA funB

Copyright © 2006, SAS Institute Inc. All rights reserved. Scope – Independent “x” Variable function funB(value); x = value * 100; put 'In funB:' x=; return (x); endsub; function funA(value); x = value; put 'In funA:' x=; y = funB(x); return (y*10); endsub; data _null_; x = funA(5); put 'In DATA Step: ' x=; run;

Copyright © 2006, SAS Institute Inc. All rights reserved. Scope – Usage data _null_; x = funA(5); put 'In DATA Step:‘ x=; run; Output to the SAS Log:  In funA: x=5  In funB: x=500  In DATA Step: x=5000

Copyright © 2006, SAS Institute Inc. All rights reserved. Function Management  Protecting Functions  Listing the Source  Adding a Function  Removing a Function  Replacing a Function

Copyright © 2006, SAS Institute Inc. All rights reserved. Protecting Functions  Operating System File Permissions Unix: chmod Windows: attrib z/OS: RACF  libname perm "\\shared\perm" access=readonly;  SAS/Share Read-Only Library

Copyright © 2006, SAS Institute Inc. All rights reserved. Listing the Function Source proc fcmp outlib=sasuser.funcs.trial; listfunc study_day;

Copyright © 2006, SAS Institute Inc. All rights reserved. Adding a Function proc fcmp outlib=sasuser.funcs.trial; function study_day(start, event); n = event – start; if n >= 0 then n = n + 1; return(n); endsub;

Copyright © 2006, SAS Institute Inc. All rights reserved. Removing a Function proc fcmp outlib=sasuser.funcs.trial; deletefunc study_day;

Copyright © 2006, SAS Institute Inc. All rights reserved. Replacing a Function proc fcmp outlib=sasuser.funcs.trial; deletefunc study_day; function study_day(start, event);...

Copyright © 2006, SAS Institute Inc. All rights reserved. Replacing a Function

Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP - Data Step Statements Not Supported  Data  Set  Merge  Update  Modify  Input  Infile (thru functions OPEN-FETCH, …)

Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP – Power of Put  Use Put for debugging Results of a Put statement can go to the PRINT (default) and LOG destinations … FILE log; Put variable ;

Copyright © 2006, SAS Institute Inc. All rights reserved. Acknowledgements and Questions  Thanks to GASUG for the invitation to present!  Thanks to Jason Secosky who provided a subset of the material for this presentation