The Dataset class provides an interface to individual SAS datasets in SLC.
It allows you to query dataset properties like the number of observations
and variables, and provides methods for dataset operations.
Details
Dataset objects are typically created by opening existing datasets through a Library object, rather than being constructed directly. The class provides methods to:
Get dataset dimensions (number of rows and columns)
Close the dataset when finished
Convert to R data frames (via PROC EXPORT)
Methods
Method close()
Close the dataset and free resources
Method to_dataframe()
Convert dataset to an R data frame
Examples
if (FALSE) { # \dontrun{
# Open a dataset through a library
slc <- Slc$new()
work_lib <- slc$get_library("WORK")
# Create some test data first
slc$submit('
data test;
do i = 1 to 100;
x = ranuni(123);
y = i * 2;
output;
end;
run;
')
# Open the dataset
dataset <- work_lib$open_dataset("test")
# Get dimensions
nrows <- dataset$get_nobs() # 100
ncols <- dataset$get_nvars() # 3 (i, x, y)
# Close when done
dataset$close()
} # }
## ------------------------------------------------
## Method `Dataset$new`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Usually created via Library$open_dataset() rather than directly
dataset <- work_lib$open_dataset("mytable")
} # }
## ------------------------------------------------
## Method `Dataset$close`
## ------------------------------------------------
if (FALSE) { # \dontrun{
dataset <- work_lib$open_dataset("mytable")
# ... work with dataset ...
dataset$close()
} # }
## ------------------------------------------------
## Method `Dataset$get_nobs`
## ------------------------------------------------
if (FALSE) { # \dontrun{
dataset <- work_lib$open_dataset("mytable")
nrows <- dataset$get_nobs()
cat("Dataset has", nrows, "observations\n")
} # }
## ------------------------------------------------
## Method `Dataset$get_nvars`
## ------------------------------------------------
if (FALSE) { # \dontrun{
dataset <- work_lib$open_dataset("mytable")
ncols <- dataset$get_nvars()
cat("Dataset has", ncols, "variables\n")
} # }
## ------------------------------------------------
## Method `Dataset$to_dataframe`
## ------------------------------------------------
if (FALSE) { # \dontrun{
# Use this instead:
work_lib <- slc$get_library("WORK")
df <- work_lib$get_dataset_as_dataframe("mytable")
} # }