1 / 14

Using SAS PROC FCMP

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

avent
Download Presentation

Using SAS PROC FCMP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using SAS PROC FCMP Cheryl Xiyun Wang Statistics Canada November 14 2012

  2. 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 • Questions Statistics Canada • Statistique Canada Page 2

  3. 1. Introduction 1) What is PROCFCMP? • 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); Statistics Canada • Statistique Canada Page 3

  4. 1. Introduction (cont’d) 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; Statistics Canada • Statistique Canada Page 4

  5. 1. Introduction (cont’d) 3) PROC FCMP Syntax PROC FCMP options; (declare statements; program statements;) ABORT; ARRAYname[dimensions] </NOSYMBOLS | variables | constants | (initial-values)>; ATTRIBvariables <FORMAT=format-name LABEL='label' LENGTH=length>; LABELvariable='label'; STRUCTstructure-name variable; DELETEFUNCfunction-name; DELETESUBRsubroutine-name; FUNCTIONfunction-name(argument-1, ..., argument-n) options SUBROUTINEsubroutine-name (argument-1, ..., argument-n) options OUTARGSout-argument-1, ..., out-argument-n; LISTFUNCfunction-name; LISTSUBRsubroutine-name; QUIT; Statistics Canada • Statistique Canada Page 5

  6. 1. Introduction (cont’d) 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); • outargsout-argument-1, ..., out-argument-N; • program-statements; • return; endsub; Here program-statements are built using SAS programming languages Statistics Canada • Statistique Canada Page 6

  7. 2. Examples of using PROC FCMP 1) Simple examples of using PROC FCMP functions/CALL routines Demo! 2) An example of using PROC FCMP in functions in PROC OPTMODEL Demo! Statistics Canada • Statistique Canada Page 7

  8. 3. Customized Functions in G-Sam 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; Statistics Canada • Statistique Canada Page 8

  9. 3. Customized Functions in G-Sam (Cont’d) 3) An example of G-Sam functions and their usage (Demo) Statistics Canada • Statistique Canada Page 9

  10. 3. Customized Functions in G-Sam (Cont’d) 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; Statistics Canada • Statistique Canada Page 10

  11. 4. Run data step within another data step through PROC FCMP • 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_nare PROC FCMP variables to be passed to macro variables in the invoked SAS Macro; then invoked SAS Macro can execute properly. 2) Demo Statistics Canada • Statistique Canada Page 11

  12. 5. Other features in PROC FCMP 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 Statistics Canada • Statistique Canada

  13. 6. References • SAS 9.3 installed locally, use SAS 9.3 Help Files Contents -> 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 Statistics Canada • Statistique Canada Page 13

  14. 7. Questions • Yves Deguire Systems Chief, SAS Technology Center, Statistics Canada, 150 Tunney's Pasture Driveway Ottawa, Ontario, K1A 0T6 Yves.Deguire@a.statcan.gc.ca (613) 951-1282 • Cheryl Wang IT Team Leader, SAS Technology Center, Statistics Canada, 150 Tunney's Pasture Driveway Ottawa, Ontario, K1A 0T6 Cherylxiyun.wang@a.statcan.gc.ca (613) 951-0843 Statistics Canada • Statistique Canada

More Related