Using SAS PROC FCMP

Preview:

DESCRIPTION

Using SAS PROC FCMP . Cheryl Xiyun Wang Statistics Canada November 14 2012. Using SAS PROC FCMP. Introduction Examples of Using PROC FCMP Using PROC FCMP to Build Customized SAS Functions in G-Sam DATA Step Runs Another DATA Step Through PROC FCMP Other Features in PROC FCMP References - PowerPoint PPT Presentation

Citation preview

Using SAS PROC FCMP

Cheryl Xiyun WangStatistics CanadaNovember 14 2012

1. Introduction2. Examples of Using PROC FCMP3. Using PROC FCMP to Build Customized SAS

Functions in G-Sam4. DATA Step Runs Another DATA Step Through

PROC FCMP5. Other Features in PROC FCMP6. References7. Questions

Statistics Canada • Statistique Canada 13/11/2012

Using SAS PROC FCMP

Page 2

Statistics Canada • Statistique Canada

1. Introduction1) What is PROC FCMP? PROC FCMP is the SAS Function Compiler procedure; it enables

us to create and test customized “functions/CALL routines” using DATA step syntax and store them in SAS packages to be shared;

Some PROC FCMP statements are slightly different from DATA step statements and we can use most features of SAS programming language to create PROC FCMP “functions/CALL routines” (variables, constants, control flows, math operations...);

Just like any other SAS “functions/CALL routines”, PROC FCMP “functions/CALL routines” can be used in DATA step, WHERE statement, Output Delivery System (ODS), and many SAS procedures (although not all);

13/11/2012Page 3

2) Advantages of using PROC FCMP A library of reusable “functions/ CALL routines” can be built using

DATA step syntax, which can be reused in many other SAS programs;

Complex programs can be simplified by abstracting/wrapping common computations into PROC FCMP “functions/ CALL routines”;

PROC FCMP “functions/CALL routines” are independent from their use which means any SAS program calling PROC FCMP functions/CALL routines is not affected by the implementation of PROC FCMP functions/CALL routines; (comparing to macros)

Developers can more easily read, write, and maintain complex code with independent and reusable functions/CALL routines;

1. Introduction (cont’d)

Statistics Canada • Statistique Canada 13/11/2012Page 4

Statistics Canada • Statistique Canada

3) PROC FCMP SyntaxPROC FCMP options; (declare statements; program statements;)

ABORT;ARRAY name[dimensions] </NOSYMBOLS | variables | constants | (initial-values)>;ATTRIB variables <FORMAT=format-name LABEL='label' LENGTH=length>; LABEL variable='label';STRUCT structure-name variable;DELETEFUNC function-name;DELETESUBR subroutine-name;FUNCTION function-name(argument-1, ..., argument-n) optionsSUBROUTINE subroutine-name (argument-1, ..., argument-n) options OUTARGS out-argument-1, ..., out-argument-n; LISTFUNC function-name;LISTSUBR subroutine-name;

QUIT;

1. Introduction (cont’d)

13/11/2012Page 5

Statistics Canada • Statistique Canada

4) Declare PROC FCMP Functions and CALL Routines

Function name(argument-1, ... , argument-n);

program-statements;return (expression);

endsub;

Subroutine name(argument-1, ..., argument-n);

outargs out-argument-1, ..., out-argument-N;program-statements;return;

endsub;

Here program-statements are built using SAS programming languages

1. Introduction (cont’d)

13/11/2012Page 6

Statistics Canada • Statistique Canada

1) Simple examples of using PROC FCMP functions/CALL routinesDemo!

2) An example of using PROC FCMP in functions in PROC OPTMODELDemo!

2. Examples of using PROC FCMP

13/11/2012Page 7

Statistics Canada • Statistique Canada

1) Situation A group of complex mathematical functions are used many

times in our large optimization problems which are to be implemented by SAS PROC OPTMODEL;

2) Solution Using PROC FCMP to build customized SAS functions for

those complex mathematical functions; Using these customized SAS Functions in any places in SAS

PROC OPTMODEL;

3. Customized Functions in G-Sam

13/11/2012Page 8

Statistics Canada • Statistique Canada

3) An example of G-Sam functions and their usage (Demo)3. Customized Functions in G-Sam (Cont’d)

13/11/2012Page 9

4) Benefit of Using PROC FCMP in G-Sam Perfect fit; wrap complex computations into independent

functions and plug them into PROC OPTMODEL easily; eases our system implementation;

Work of building PROC FCMP functions be done independently by another developer (parallel); efficient

Easy maintenance: from times to time, specs changes a lot but are mostly in these functions, thus most system modifications were done in the FCMP functions; less impact;

Numeric precision needs special attentions. Don’t use customized functions in PROC Optmodel variables;

3. Customized Functions in G-Sam (Cont’d)

Statistics Canada • Statistique Canada 13/11/2012Page 10

1) PROC FCMP run_macro(…) function; rc = RUN_MACRO ('macro_name', variable_1, variable_2, ...,

variable_n) ;

where: the return code rc indicates that the macro call was attempted; variable_1, variable_2, ..., variable_n are PROC FCMP variables to be passed to macro variables in the invoked SAS Macro; then invoked SAS Macro can execute properly.

2) Demo

4. Run data step within another data step through PROC FCMP

Statistics Canada • Statistique Canada 13/11/2012Page 11

Statistics Canada • Statistique Canada

1) SAS FCMP Function Editor SAS 9.2 / SAS 9.3 -> Solutions -> Analysis -> FCmp Function Editor Browse / edit all available PROC FCMP functions/CALL routines; Syntax

checking; testing; manage datasets and logs ;

2) Enables calling c/c++ functions from Data Step Data Step -> PROC FCMP wrapper functions –> Proc proto functions –

> c/c++ functions Good paper: Developing

User-Defined Functions in SAS®: A Summary and Comparison

3) Build-in Microsoft Excel functions

4) Build-in functions for Matrix operations

5. Other features in PROC FCMP

13/11/2012Page 12

SAS 9.3 installed locally, use SAS 9.3 Help FilesContents -> SAS Products -> Base SAS -> Base SAS 9.3 Procedures Guide ->

Procedures -> FCMP Procedure / FCMP Special Functions and Call Routines / FCmp Function Editor

SAS 9.3 not installed, Check SAS online document: PROC FCMP :: Base SAS(R) 9.3 Procedures Guide, Second Edition

Developing User-Defined Functions in SAS®: A Summary and Comparison(comparing Macro, SAS/IML, SCL, Proc Proto and Proc FCMP: how to build and

performance) Functioning at an Advanced Level: PROC FCMP and PROC PROTO

(simple examples) Overview of the SAS Function Compiler (FCMP – GASUG) Top 10 reasons for a modeller to learn PROC FCMP (Financial market analyst): Google “PROC FCMP” Difference between proc fcmp and datastep

6. References

Statistics Canada • Statistique Canada 13/11/2012Page 13

Yves DeguireSystems Chief, SAS Technology Center, Statistics Canada, 150 Tunney's Pasture DrivewayOttawa, Ontario, K1A 0T6Yves.Deguire@a.statcan.gc.ca(613) 951-1282

Cheryl WangIT Team Leader, SAS Technology Center, Statistics Canada, 150 Tunney's Pasture DrivewayOttawa, Ontario, K1A 0T6Cherylxiyun.wang@a.statcan.gc.ca(613) 951-0843

7. Questions

Page 14 Statistics Canada • Statistique Canada 13/11/2012

Recommended