The mcr_sas Module

Abstract base class for processing semi-structured Medicare SAS files (1999–2010).

This class provides common traversal and filename-parsing logic to identify and process Medicare data files stored in the SAS 7BDAT format.

These files are partially preprocessed and typically include:

Denominator (patient/enrollment) files Inpatient admissions files Subclasses must implement the abstract handle() method to specify file handling logic.

Typical usage: - :class:~dorieh.cms.tools.sas_loader.SASLoader for data ingestion - :class:~dorieh.cms.tools.sas_introspector.SASIntrospector for metadata extraction

class MedicareSAS(root_dir: str = '.')[source]

Abstract base class for locating and processing Medicare SAS 7BDAT files in a specified directory

This class handles: - Recursively locating SAS files matching given patterns - Determining file type and year from directory structure - Invoking subclass-defined logic for each discovered file

Subclasses must implement:
  • handle(table, file_path, file_type, year): method to process each file.

Attributes:

root_dir (str or List[str]): Directory or list of directories containing data files.

Initialize the MedicareSAS base class.

Args:
root_dir (str or List[str]): Root directory (or directories) containing SAS files.

This can be a single directory as a string or a list of directories.

traverse(pattern: str)[source]

Search for SAS files that match a glob-style pattern and process them.

Uses recursive glob search from the root_dir(s), filtering by .sas7bdat extension, and passes matching files to self.handle_sas_file().

Args:

pattern (str): File search pattern (e.g., “[1-2]*//.sas7bdat”).

handle_sas_file(f: str)[source]

Analyze the SAS file path to extract file type and year, then delegate the processing to subclass-defined handle() method.

Args:

f (str): Full path to the .sas7bdat file.

Raises:

ValueError: If file path does not contain a recognizable year or type.

abstract handle(table: str, file_path: str, file_type: str, year: int)[source]

Abstract method to handle a single SAS 7BDAT file.

This must be implemented by any subclass of MedicareSAS, and should define how a given SAS dataset is processed.

Concrete classes override it to either generata database schema or perform data loading

Args:

table (str): Name of the table or logical target in the system. file_path (str): Full file path to the SAS file. file_type (str): Subtype or directory name used to classify the file (e.g., “inpatient”, “denominator”). year (int): Parsed year value inferred from directory name.