Skip to Main Content
SAS for R Users
book

SAS for R Users

by Ajay Ohri
September 2019
Beginner to intermediate content levelBeginner to intermediate
208 pages
3h 17m
English
Wiley
Content preview from SAS for R Users

8Functions, Loops, Arrays, Macros

In this chapter, we study ways to make things more automated by using functions in R and Macro Language in SAS. In addition, we study loops (for and do) as well as arrays in SAS.

8.1 Functions

In R Functions in R are quite easy in Syntax. They are of the form:

FUNCTIONNAME+function(x,y,..parameters){ function description)

They are called by FUNCTIONNAME(input value)

In SAS we use Proc FMCP.

The FCMP procedures are used to write, compile, and test DATA step functions and CALL routines that can be used in DATA step. For more information, you can read http://support.sas.com/resources/papers/proceedings13/139‐2013.pdf

8.2 Loops

Loops are used for tasks that are repeatable. You can also use functions within iterations of loops. Note in SAS you need to use end to close loop and output to output data.

In SAS:

In R:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Statistical Hypothesis Testing with SAS and R

Statistical Hypothesis Testing with SAS and R

Sonja Kuhnt, Dirk Taeger

Publisher Resources

ISBN: 9781119256410Purchase book