Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Calling R Functions from SAS… PhUSE 2011 – 12.10.2011 ….with PROC IML.

Similar presentations


Presentation on theme: "Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Calling R Functions from SAS… PhUSE 2011 – 12.10.2011 ….with PROC IML."— Presentation transcript:

1 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Calling R Functions from SAS… PhUSE 2011 – 12.10.2011 ….with PROC IML

2 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH 2 Company HMS Analytical Software is a specialist for Information Technology in the field of Data Analysis and Business Intelligence Systems Profile – 40 employees in Heidelberg, Germany – SAS Institute Partner for 15 years – Doing data oriented software projects for more than 20 years – Focus on life science industry Technologies – Analytics and Data Management: SAS, JMP, R, Microsoft SQL Server – Application Development: Microsoft.NET, Java

3 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Our IT Services for the Life Science Industry (SAS, JMP, R and Microsoft) Independent Consulting Programming Data Management Data Mining / Analysis Training and Individual Coaching Application Development and Integration Software Validation 3

4 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Agenda Servey Who needs an interface to R Requirements How to submit R Code? What about data sets and SAS formats? Do I get my R Graphics into SAS-Report How to handle errors coming from R Questions that came up during PhUSE 4

5 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Degree of Popularity of R compared to PhUSE 2010 yes no 5

6 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH The Best of two Worlds 6

7 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH The Best of two Worlds 7 Client Tier Management Console Data Integration Studio Information Map Studio Enterprise Guide …. Web Tier Web Report Studio Information Delivery Portal STP Web Application …. Server Tier Connect Server SAS Foundation OLAP Server STP Server …. Data Tier Data Sets OLAP Cubes ERP data structure RDBMS Tables …. Metadata Server BioConductor Bioinformatic community Rgeo Spatial Statistics gR Graphical Models Robus Robus statistics Rmetrics Financial Market Analysis Omega Distributed Statistical Computing

8 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Who needs an Interface to R? People who don´t want a “religious” decision between SAS or R. They want both! People who want to use one of the huge amount of add-on-packages of R Lazy people, who don´t want to convert their existing R code to SAS People who switch from R to SAS People who want to validate their SAS programs (Nikhil Abhyankar, yesterday talk) 8

9 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH SAS/IML as an Interface to R SAS Interactive Matrix Language (IML) is a programming language for explorative data analysis. wide range of most standard matrix operations direct access to SAS data sets create dynamic graphics 9 it has the an interface to R PROC IML use this interface

10 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Requirements to Use PROC IML as an Interface to R 10 SAS 9.22SAS 9.3 32-bit and 64-bit Windowsxx 32-bit and 64-bit Linux-x 32-bit version of Rxx 64-bit version of R-x Supported R VersionsR-2.11.1 or before ?? R must be installed on the same computer / server access to the SAS workspace server via Enterprise Guide®

11 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH How to submit R Code 1. Start SAS with the RLANG-option (C:\...\sas.exe -RLANG). 2. Check access to R NORLANG:Do not support access to R language interfaces ERROR: The RLANG system option must be specified in the SAS configuration file or on the SAS invocation command line to enable the submission of R language statements. WARNING: SAS option RLANG is not supported on this host. RLANG:Support access to R language interfaces 11

12 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH How to submit R Code 3. Use PROC IML as the interface to R 12

13 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Sending Data from SAS to R and back - IML built-in subroutines- From SAS to R: 13 SubroutineSAS SourceR Destination ExportDataSetToRSAS data setR data frame ExportMatrixToRSAS/IML matrixR matrix SubroutineR SourceSAS Destination ImportDataSetFromRR expressionSAS data set ImportMatrixFromRR expressionSAS/IML matrix From R to SAS:

14 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Sending SAS Data Sets to R 14

15 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Getting SAS Data Sets back from R 15

16 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH What about Date, Times and Datetime Values? From SAS to R: 16 SASR Date (e.g. DATEw.d)Class „Date“ Datetime (e.g. DATETIMEw.d)Classes that inherit from Class „POSIXT“ Time (e.g. TIMEw.d)Classes inherit from Class „POSIXT“ All other formatsClass „numeric“

17 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH What about Date, Times and Datetime Values? From R to SAS: 17 RSAS Class „Date“DATE9. Class „POSIXT“TIME19. In all other casesno SAS format is assigned

18 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Get Graphics from R to SAS 18

19 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Get Graphics from R to SAS 19

20 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Handling Errors from R Error: Division by a alphanumeric variable: 1.have a look to the SAS LOG 20

21 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Handling Errors from R 2. read out the global SAS macro variable SYSERRORTEXT (holds the last error message) 21

22 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Handling Errors from R 3. Use tryCatch-block in R and write the error message to a SAS data set 22

23 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Handling Errors from R 3. Use tryCatch-block in R and write the error message to a SAS data set 23

24 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Limitations No option to tell SAS which R to use. Large data sets are limited by memory size – In R the data are load and processed in the main memory. The same is true for SAS IML. R comes along with absolutely no warranty – take this especially into account for the large amount of add-on-packages. Not all data types from R can be converted – every data type has to be converted either to a data.frame or a matrix before transferring data to SAS 24

25 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Questions during PhUSE… What is faster SAS or R? 25

26 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Questions during PhUSE… Is PROC IML the only way to run R programs? 26

27 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Questions during PhUSE… Is R easy to learn? 27

28 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Questions during PhUSE… Is R easy to learn? 28 2-day-training course, HMS

29 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Questions during PhUSE… Is are a validated environment? no, it is NOT: R comes along with absolutely no warranty 29

30 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Conclusion The best of two worlds. SAS implements a powerful interface to R within PROC IML. SAS data sets can be send to R and back. Some SAS formats are converted to R counterpart. R graphics can be integrated into SAS PDF-reports. Different ways to handle errors from R in SAS. 30

31 Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH 31 Thank you for your Attention Dr. Peter Bewerunge Software Engineer HMS Analytical Software GmbH Rohrbacher Str. 26 69115 Heidelberg Telefon +49 6221 6051-0 Peter.Bewerunge@analytical-software.de www.analytical-software.de Dr. Peter Bewerunge Software Engineer HMS Analytical Software GmbH Rohrbacher Str. 26 69115 Heidelberg Telefon +49 6221 6051-0 Peter.Bewerunge@analytical-software.de www.analytical-software.de


Download ppt "Dr. Peter Bewerunge © 2009 HMS Analytical Software GmbH Calling R Functions from SAS… PhUSE 2011 – 12.10.2011 ….with PROC IML."

Similar presentations


Ads by Google