Chapter 24 (4th ed.): Creating Functions

Slides:



Advertisements
Similar presentations
Chapter 5: Creating and Managing Tables using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Advertisements

Spring Semester 2013 Lecture 5
Procedures and Functions. What are they? They are both blocks of code that can be reused to perform specific task. However there is a difference: Function-
Copyright © 2006, SAS Institute Inc. All rights reserved. Proc FCMP – Data Step Functions
Chapter 9: Introducing Macro Variables 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Performing Queries Using PROC SQL Chapter 1 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 13: Creating Samples and Indexes 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
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.
Using SAS PROC FCMP Cheryl Xiyun Wang Statistics Canada
Chapter 3: Combining Tables Horizontally using PROC SQL 1 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 10:Processing Macro Variables at Execution Time 1 STAT 541 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina Chapter 17 supplement: Review of Formatting Data STAT 541.
Chapter 15: Combining Data Horizontally 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Chapter 16: Using Lookup Tables to Match Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
Chapter 17: Formatting Data 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Chapter 19: Introduction to Efficient SAS Programming 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
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.
Chapter 4: Combining Tables Vertically using PROC SQL 1 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 17 Supplement: Alternatives to IF-THEN/ELSE Processing STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South.
Chapter 23: Selecting Efficient Sorting Strategies 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 21: Controlling Data Storage Space 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 14: Combining Data Vertically 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 11–Macro-Processors.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Chapter 9: Value-Returning Functions
Chapter Topics The Basics of a C++ Program Data Types
Chapter 7 User-Defined Methods.
Chapter 5: Enhancing Your Output with ODS
Java Primer 1: Types, Classes and Operators
C Language By Sra Sontisirikit
UNIT - V STORED PROCEDURE.
Organization of Programming Languages
Chapter 19: Introduction to Efficient SAS Programming
Method.
Chapter 3: Working With Your Data
Chapter 13: Creating Samples and Indexes
PL/SQL Scripting in Oracle:
11/10/2018.
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Chapter 18: Modifying SAS Data Sets and Tracking Changes
Former Chapter 23: Selecting Efficient Sorting Strategies
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 ©
Chapters 5 and 7 supplement
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.
Defining and Calling a Macro
How are your SAS Skills? Chapter 1: Accessing Data (Question # 1)
Chapter 4 –Requirements for coding in Assembly Language
Chapter 4 –Requirements for coding in Assembly Language
Using Macros to Solve the Collation Problem
Chapter 9: Value-Returning Functions
Chapter 24: Querying Data Efficiently
Tutorial 11 Using and Writing Visual Basic for Applications Code
Preprocessor Directives and Macros Chapter 21
Presentation transcript:

Chapter 24 (4th ed.): Creating Functions STAT 541 Chapter 24 (4th ed.): Creating Functions ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina

Outline About PROC FCMP Creating a Function Creating a Subroutine

PROC FCMP Syntax PROC FCMP statement must come first. The OUTLIB= option (which specifies a 3-level name of an output package where the compiled functions are stored) is REQUIRED. The FUNCTION statement gives the name of the function (with one or more optional arguments) and indicates the type of value (character or numeric) that is returned by the function. The RETURN statement specifies the value that is returned by the function. The ENDSUB statement ends the function definition. 3

Using the Function To use the function in a DATA step or in a PROC step, you must first specify the CMPLIB= system option. Here you specify the 2-level name of the data set where the functions are stored. Then the function can be used in a DATA step or in certain supported PROC steps. 4

Creating a Subroutine with PROC FCMP The SUBROUTINE statement in PROC FCMP names a block of code with parameters that can be used later. The subroutine is similar in purpose to a macro. The OUTARGS statements lists the output parameters that get updated when the subroutine runs. 5

Differences between Functions and Subroutines A function is an expression and returns a value, whereas a subroutine is a statement and modifies arguments. A function can be part of a SAS statement, whereas a subroutine is always used with a CALL statement. Function Subroutine Is an Expression Is a Statement Returns a Value Modifies arguments Used in a statement Used with CALL 6

Using Functions and Subroutines Created with PROC FCMP Most SAS programming language features can be used similarly in PROC FCMP In the DATA step, you can call function and subroutines you’ve created just as you can call any built-in SAS functions and subroutines Created functions and subroutines can be used in some procedures, such as PROC GENMOD, PROC MODEL, PROC MCMC, PROC NLIN, PROC NLMIXED, and others. 7

Examples of Functions and Subroutines The “ReverseName” function works on character variables. See example of simple inverse subroutine. The “Win Percentage” subroutine can be used on several variables. The “Years Until Turning 65” subroutine works with date variables. 8