Skip to content
Prev 169292 / 398502 Next

Numeric class and sasxport.get

I also realized the flaw after testing the script on various datasets...

Following up on your last note:
1- Is that the reason why the class of integer and regular numeric 
variable is solely "labelled" following sasxport.get?
2- Can class be 'soft' for other 'kind' of variables?
3- Would you anticipate the following wrapper function to generate 
incompatibilities with other R functions?


SASxpt.get <- function(file, force.single = TRUE,
                  method=c('read.xport','dataload','csv'), formats=NULL, 
allow=NULL,
                  out=NULL, keep=NULL, drop=NULL, as.is=0.5, FUN=NULL) {
 
  foo <- sasxport.get(file=file, force.single=force.single, method=method,
                      formats=formats, allow=allow, out=out, keep=keep,
                      drop=drop, as.is=as.is, FUN=FUN)
 
  # For each variable of class "labelled" (and only "labelled"), add the 
native class as a second class argument

  sglClassVarInd <- which(lapply(lapply(unclass(foo),class),length)==1)
 
  for (i in 1:length(sglClassVarInd)){
    x <- foo[,sglClassVarInd[i]]   
    if (class(x)=="labelled") class(foo[,sglClassVarInd[i]]) <- 
c(class(x), class(unclass(x)))
  }
  return(foo)
}


*Sebastien Bihorel, PharmD, PhD*
PKPD Scientist
Cognigen Corp
Email: sebastien.bihorel at cognigencorp.com 
<mailto:sebastien.bihorel at cognigencorp.com>
Phone: (716) 633-3463 ext. 323
Frank E Harrell Jr wrote: