SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML –...

18
Copyright © 2006, SAS Institute Inc. All rights reserved. Saskatchewan SAS User Group 28APR2010 SAS/IML Sylvain Tremblay SAS Canada – Education

Transcript of SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML –...

Page 1: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Copyright © 2006, SAS Institute Inc. All rights reserved.

Saskatchewan SAS User Group 28APR2010

SAS/IML

Sylvain Tremblay SAS Canada – Education

28APR2010

Page 2: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

SAS/IML – Interactive M

Copyright © 2006, SAS Institute Inc. All rights reserved.

In IML, the code is: A*B

Matrix Language

In IML, the code is: A*B

Page 3: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Agenda

§ Summary of IML

§ Why would you use IML?

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Basic Syntax

§ Example

§ SAS/IML Studio

§ Conclusion / Questions

Why would you use IML?

Page 4: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Summary of SAS/IML

§ Is a programming language

§ Is Interactive

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Is Dynamic

§ Is using data matrices as a fundamental object

§ Has a powerful vocabulary of operators

§ Can also produces graphics

Is a programming language

as a fundamental object

Has a powerful vocabulary of operators

Can also produces graphics

Page 5: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Why would you use IML?

Typically, because you need to:

§ solve mathematical problems

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ solve mathematical problems

§ implement new statistical techniques

Why would you use IML?

Typically, because you need to:

solve mathematical problems solve mathematical problems

implement new statistical techniques

In IML code

Page 6: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Why would you use IML?

Because you will save time!

§ programs that take hundreds of lines of code in

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ programs that take hundreds of lines of code in other languages often take only a IML!

§ IML matrix functions and operators will more quickly than their equivalents in SAS/Base

Why would you use IML?

Because you will save time!

programs that take hundreds of lines of code in programs that take hundreds of lines of code in other languages often take only a few lines in

IML matrix functions and operators will execute than their equivalents in SAS/Base

Page 7: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Basic Syntax

72 Procedures SAS/STAT has

The SAS/IML module has only 1 Proc

Copyright © 2006, SAS Institute Inc. All rights reserved.

Proc IML <options>;

IML statements;

Quit;

Commonly used option: WORKSIZE=

IML does everything in Memory !!!

72 Procedures

The SAS/IML module has only 1 Proc: Proc IML

Commonly used option: WORKSIZE=

IML does everything in Memory !!!

Page 8: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Reading Data

§ Create a Matrix from a SAS Dataset

§ Create a SAS Dataset from a Matrix

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Create a SAS Dataset from a Matrix

Matrices can be: § Character

§ Numeric

Create a Matrix from a SAS Dataset

Create a SAS Dataset from a Matrix Create a SAS Dataset from a Matrix

Page 9: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Statements in PROC IML

Four main categories

§ Control Statements

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Control Statements

§ Commands

§ Call Statements and Subroutines

§ Assignment Statements

Statements in PROC IML

Call Statements and Subroutines

Assignment Statements

Page 10: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Statements in PROC IML

Control Statements

§ IF­THEN/ELSE

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ IF­THEN/ELSE

§ DO/END

§ Iterative DO

§ START/FINISH (User defined IML subroutines)

Statements in PROC IML

(User defined IML subroutines)

Page 11: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Statements in PROC IML

Commands

§ FREE (free memory: remove values from matrix)

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ FREE (free memory: remove values from matrix)

§ PRINT (the content of a matrix)

§ READ (data from a SAS Dataset into a matrix)

§ USE (opens a SAS Dataset for READ access)

Statements in PROC IML

(free memory: remove values from matrix) (free memory: remove values from matrix)

(the content of a matrix)

(data from a SAS Dataset into a matrix)

(opens a SAS Dataset for READ access)

Page 12: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Statements in PROC IML

Call Statement and Subroutines

§ CALL subroutine­name(argument1, argument2,…)

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ CALL subroutine­name(argument1, argument2,…)

§ You can call: An IML subroutine

A User defined subroutine

Statements in PROC IML

Call Statement and Subroutines

name(argument1, argument2,…) name(argument1, argument2,…)

A User defined subroutine

Page 13: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Statements in PROC IML

Assignment Statement

§ Result = Expression

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Result = Expression

a Matrix Operands Operators Constants Functions

Statements in PROC IML

Result = Expression Result = Expression

Operands Operators Constants Functions

Page 14: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

IML Demo ­ Simple Linear Regression

§ Y = B 0 + B 1 X + e

§ Y =

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Y =

§ B is estimated by the Least Squares

Simple Linear Regression

in matrix notation in matrix notation

B is estimated by the Least Squares

Page 15: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

SAS/IML Studio

§ Runs on a PC on Windows and connects with one or

Copyright © 2006, SAS Institute Inc. All rights reserved.

§ Runs on a PC on Windows and connects with one or more SAS servers

§ Available in SAS 9.2, requires BASE, STAT and IML

§ Point­and­click tool for exploratory data analysis (replaces SAS/Insight)

§ Programming environment § Uses the IML Plus language (IML + call SAS + call R)

Runs on a PC on Windows and connects with one or Runs on a PC on Windows and connects with one or

Available in SAS 9.2, requires BASE, STAT and IML click tool for exploratory data analysis

Programming environment Uses the IML Plus language (IML + call SAS + call R)

Page 16: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

In conclusion

§ SAS IML is a powerful language if you need to solve mathematical problems

§ More efficient than the Data Step if you are working with matrices

Copyright © 2006, SAS Institute Inc. All rights reserved.

working with matrices

§ Very rich function and subroutine set + the capacity to create your own

§ IML Studio in which you can leverage the IML Plus language

SAS IML is a powerful language if you need to solve mathematical problems

More efficient than the Data Step if you are

Very rich function and subroutine set + the capacity to create your own

IML Studio in which you can leverage the IML

Page 17: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

To learn more

SAS/IML Documentation http://support.sas.com/documentation/cdl/en/imlug/59656/HT ML/default/imlstart.htm

Copyright © 2006, SAS Institute Inc. All rights reserved.

SAS/IML Studio http://support.sas.com/documentation/cdl/en/imlsstat/62555/H TML/default/statintro.htm

SAS Training Introduction to Programming with SAS/IML Software

To learn more

http://support.sas.com/documentation/cdl/en/imlug/59656/HT

http://support.sas.com/documentation/cdl/en/imlsstat/62555/H

Introduction to Programming with SAS/IML Software

Page 18: SAS/IML Group Presentation… · SAS/IML Sylvain Tremblay SAS Canada –Education 0. SAS/ IML – Interactive M ...

Questions?

Copyright © 2006, SAS Institute Inc. All rights reserved. Copyright © 2006, SAS Institute Inc. All rights reserved.

Thanks!

Questions?

Sylvain Tremblay [email protected]