Skip to contents

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 new()

Create a new Dataset object

Usage

Dataset$new(dataset)

Arguments

dataset

A WpsDataset object representing the SAS dataset

Returns

A new Dataset object

Examples

\dontrun{
# Usually created via Library$open_dataset() rather than directly
dataset <- work_lib$open_dataset("mytable")
}


Method close()

Close the dataset and free resources

Usage

Dataset$close()

Details

Closes the dataset connection and frees any associated resources. It's good practice to close datasets when finished with them, especially in long-running sessions.

Returns

Invisible self (for method chaining)

Examples

\dontrun{
dataset <- work_lib$open_dataset("mytable")
# ... work with dataset ...
dataset$close()
}


Method get_nobs()

Get the number of observations (rows) in the dataset

Usage

Dataset$get_nobs()

Returns

Integer number of observations

Examples

\dontrun{
dataset <- work_lib$open_dataset("mytable")
nrows <- dataset$get_nobs()
cat("Dataset has", nrows, "observations\n")
}


Method get_nvars()

Get the number of variables (columns) in the dataset

Usage

Dataset$get_nvars()

Returns

Integer number of variables

Examples

\dontrun{
dataset <- work_lib$open_dataset("mytable")
ncols <- dataset$get_nvars()
cat("Dataset has", ncols, "variables\n")
}


Method to_dataframe()

Convert dataset to an R data frame

Usage

Dataset$to_dataframe(format = "csv")

Arguments

format

Character string data format ("csv" or "parquet")

Details

This method is not yet fully implemented. Use the Library class method get_dataset_as_dataframe() instead, which uses PROC EXPORT to convert SAS datasets to R data frames.

Returns

Data frame (currently not implemented)

Examples

\dontrun{
# Use this instead:
work_lib <- slc$get_library("WORK")
df <- work_lib$get_dataset_as_dataframe("mytable")
}


Method clone()

The objects of this class are cloneable with this method.

Usage

Dataset$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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")
} # }