R/zgetsas.R

Defines functions getSAS

Documented in getSAS

##' Run SAS code like in the following:
##'
##' ODS CSVALL BODY="myest.csv";
##' proc nlmixed data=aj qpoints=2 dampstep=0.5;
##' ...
##' run;
##' ODS CSVALL Close;
##'
##' and read results into R with:
##'
##' \code{getsas("myest.csv","Parameter Estimates")}
##'
##' @title Read SAS output
##' @param infile file (csv file generated by ODS)
##' @param entry Name of entry to capture
##' @param \dots additional arguments to lower level functions
##' @author Klaus K. Holst
##' @export
##' @seealso getMplus
getSAS <- function(infile,entry="Parameter Estimates",...) {
    con <- file(infile, blocking = FALSE)
    inp <- readLines(con)
    close(con)
    linestart <- 1; lineend <- length(inp)
    idx <- sapply(inp,function(x) length(grep(entry, x))>0)
    if (sum(idx)==1) {
        linestart <- which(idx)
        for (i in seq(linestart,length(inp))) {
            lineend <- i-1
            if (inp[i]=="") break;
        }
    } else {
        stop("No match or duplicate entries!")
    }
    subinp <- inp[(linestart+1):(lineend)]
    con <- textConnection(subinp)
    res <- read.csv(con,header=TRUE)
    close(con)
    return(res)
}

Try the lava package in your browser

Any scripts or data that you put into this service are public.

lava documentation built on Nov. 5, 2023, 1:10 a.m.