Last active
October 12, 2015 17:01
-
-
Save benjamin-chan/73019d049763cff1d448 to your computer and use it in GitHub Desktop.
R script to call SAS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callSAS <- function (f, path=tempdir(), workDir=sprintf("E:\\Share\\Temp\\%s\\SASWork", Sys.info()["user"])) { | |
# Usage: | |
# > callSAS("getClaimsMed.sas") | |
if (grepl(".sas$", f)) { | |
exeFile <- "C:\\Program Files\\SASHome\\SASFoundation\\9.3\\sas.exe" | |
sasFile <- sprintf("%s\\%s", path, f) | |
logFile <- sprintf("%s\\%s", path, gsub(".sas$", ".log", f)) | |
cmd <- sprintf("\"%s\" -sysin \"%s\" -log \"%s\" -print \"%s\" -work \"%s\"", | |
exeFile, | |
sasFile, | |
logFile, | |
logFile, | |
workDir) | |
system(cmd, invisible=FALSE) | |
cat(readLines(sasFile), sep="\n") | |
if (length(grep("^ERROR:", readLines(logFile)) > 0)) { | |
warning(sprintf("\nERROR: See line %s in %s.", grep("^ERROR:", readLines(logFile)), logFile)) | |
} else { | |
message(sprintf("No errors\nSee %s for details.", logFile)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment