0

Anyone knows how to ignore/skip error while getting SAS export format file into R?

require(SASxport)
asc = SASxport::read.xport("..\\LLCP2018.XPT_", keep = cols)

Checking if the specified file has the appropriate header

Extracting data file information...

Reading the data file... ### Error in [.data.frame(ds, whichds) : undefined columns selected

I have plenty of columns and don't want to check one-by-one if it really exists. Would like to ignore missing but there's no option within the function.

EDIT

Found an easy solution:

lu = SASxport::lookup.xport(xfile)

Now can probably choose from lu$names and intersect with cols. Still not every variables can be read but it's better.

But when I choose few columns (checked) I get another error unable to skip:

Error in if (any(tooLong)) { : missing value where TRUE/FALSE needed

Why this stops the reading process and returns null?

EDIT 2

Found workaround reading the same function but from different package:

asc <- foreign::read.xport(xfile)

Works, unfortunately, loads whole data - if there's some size limitation probably nothing I could do.

Peter.k
  • 1,475
  • 23
  • 40
  • Hard to tell what the question is. Are you saying you have a list of VARIABLE names that you want to pass to the read.xport function so that it only keeps those variables when making the R object? But some of the names in your list are not actually in the SAS xport file? – Tom Mar 26 '20 at 13:42
  • Some of variables shown in lookup can't be read due to first error (not found - but verbose doesn't say which), some other due to missing values (says which, but don't know how to continue reading) – Peter.k Mar 26 '20 at 13:46

0 Answers0