{"library":"sas7bdat","title":"SAS7BDAT File Reader","description":"The `sas7bdat` library provides a Pythonic way to read SAS `.sas7bdat` files, making it easy to convert them into pandas DataFrames. As of version 2.2.3, it offers robust parsing capabilities for various SAS file versions and handles common encoding challenges. The library generally releases updates for bug fixes and minor feature enhancements.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install sas7bdat"],"cli":null},"imports":["from sas7bdat import SAS7BDAT"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport pandas as pd\nfrom sas7bdat import SAS7BDAT\n\n# For demonstration, ensure a 'sample.sas7bdat' file exists or provide a path\n# You can often find sample .sas7bdat files online or create dummy ones for testing.\n# Replace with your actual file path or set SAS_FILE_PATH environment variable.\nfile_path = os.environ.get('SAS_FILE_PATH', 'sample.sas7bdat')\n\ntry:\n    if not os.path.exists(file_path):\n        print(f\"Warning: '{file_path}' not found. Quickstart cannot run without a SAS file.\")\n        print(\"Please provide a .sas7bdat file or set the SAS_FILE_PATH environment variable.\")\n    else:\n        # It's crucial to specify the correct encoding for your SAS file.\n        # 'latin-1', 'cp1252', or 'utf-8' are common choices.\n        with SAS7BDAT(file_path, encoding='latin-1') as reader:\n            df = reader.to_data_frame()\n            print(f\"Successfully read {len(df)} rows and {len(df.columns)} columns.\")\n            print(\"First 5 rows of the DataFrame:\")\n            print(df.head())\nexcept FileNotFoundError:\n    print(f\"Error: The file '{file_path}' was not found. Check the path.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"Reads a `.sas7bdat` file, automatically inferring metadata, and converts it into a pandas DataFrame. Emphasizes the use of a context manager and the importance of specifying the correct file encoding.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}