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:

Get SAS for R Users now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.