R to Viya

可參考Github SAS Scripting Wrapper for Analytics Transfer (SWAT) for R
SWAT下載位置
縮寫 CAS = SAS Cloud Analytics Services

首先確認,版本可參考上方連結
# Make sure prerequisites are installed
> install.packages('dplyr')
> install.packages('httr')
> install.packages('jsonlite')
>install.packages('https://github.com/sassoftware/R-swat/releases/download/vX.X.X/R-swat-X.X.X-platform.tar.gz',repos=NULL, type='file')
若有安裝devtools
> library(devtools)
> devtools::install_github(repo='sassoftware/R-swat')



Connecting to CAS

> library(swat)
> conn <- swat::CAS('host', 8777, protocol='http', username='sasdemo', password='******')

CAS狀態,檢視CAS內資料
> view(cas.builtins.serverStaus(conn))
> cas.table.tableInfo(conn)$TableInfo
Load table (Github範例)
# Load Iris data set into in-memory table
> iris.ct <- as.casTable(conn, iris)
# Use basic R functions on CAS table
> min(iris.ct$Sepal.Length)
[1] 4.3

# Call CAS actions on the table
> out <- cas.simple.summary(iris.ct)
> out
$Summary
        Column Min Max   N NMiss     Mean   Sum       Std     StdErr       Var
1 Sepal.Length 4.3 7.9 150     0 5.843333 876.5 0.8280661 0.06761132 0.6856935
2  Sepal.Width 2.0 4.4 150     0 3.057333 458.6 0.4358663 0.03558833 0.1899794
3 Petal.Length 1.0 6.9 150     0 3.758000 563.7 1.7652982 0.14413600 3.1162779
4  Petal.Width 0.1 2.5 150     0 1.199333 179.9 0.7622377 0.06223645 0.5810063
      USS       CSS       CV   TValue         ProbT
1 5223.85 102.16833 14.17113 86.42537 3.331256e-129
2 1430.40  28.30693 14.25642 85.90830 8.004458e-129
3 2582.71 464.32540 46.97441 26.07260  2.166017e-57
4  302.33  86.56993 63.55511 19.27060  2.659021e-42
結束
> cas.session.endSession(conn)
有關log的筆記
All of the servers and services in a SAS Viya environment produce log files, which are stored in the following location:
/opt/sas/<deployment_name>/config/var/log/<productName>



留言