SAS Datasets: Temporary and Permanent Data Sets

A SAS dataset is a structured file that SAS can read, process, and update. It stores observations as rows and variables as columns, together with descriptor information such as variable names, data types, lengths, labels, and formats.

SAS normally identifies a dataset with a two-level name in the form libref.member-name. For example, WORK.SALES identifies the SALES dataset in the WORK library. The library determines where the dataset is stored, while the member name identifies the individual dataset.

Temporary and Permanent SAS Datasets

SAS datasets are commonly classified as temporary or permanent according to the library in which they are stored.

Dataset typeTypical libraryHow long it remains availableSuitable use
Temporary SAS datasetWORKUntil the current SAS session endsIntermediate calculations, sorting, filtering, and test results
Permanent SAS datasetA user-defined libraryAfter the SAS session ends, provided that the storage location remains availableReusable source data, final results, and datasets needed in later sessions

Temporary SAS datasets in the WORK library

SAS creates the WORK library when a session starts. A dataset saved as WORK.DATASET1 is temporary and is normally removed when that SAS session closes. If a one-level dataset name such as DATASET1 is used without another default library being configured, SAS generally creates it in WORK.

Permanent SAS datasets in an assigned library

To retain a dataset, assign a library reference to a persistent directory or another supported data source and use that libref in the dataset name. A LIBNAME statement associates a short libref, such as PRASANTH, with the physical storage location. The assignment usually lasts for the current session, but the files stored at that location remain available for later sessions.

SAS Dataset Structure and File Format

  • Data portion: Contains observations and the values recorded for each variable.
  • Descriptor portion: Contains metadata such as the number of observations, variable names, variable types, lengths, labels, formats, and informats.
  • Variable types: Traditional SAS datasets use numeric and character variables. Dates and datetimes are stored as numeric values and displayed through SAS formats.
  • Native file extension: A SAS data file is commonly stored with the .sas7bdat extension. SAS views and files accessed through other engines can behave differently.

A SAS dataset is not the same as a raw CSV, spreadsheet, or text file. External files are imported or read into SAS by using an appropriate procedure, DATA step, or access engine. SAS can then store the resulting observations and metadata as a SAS dataset.

Creating a Permanent SAS Library on a Mac with VirtualBox

The following instructions apply to the VirtualBox-based SAS University Edition environment shown in the screenshots. They are useful when maintaining an existing installation that uses the /folders/myfolders shared-folder convention. In a managed SAS Studio or server environment, use a path made accessible by the SAS administrator instead.

  • Open Documents and create a folder named SASUniversityEdition. Inside it, create a subfolder named myfolders.
  • Configure the myfolders directory as a VirtualBox shared folder.
  • In VirtualBox, select the SAS University Edition vApp and then select Machine > Settings.
  • In the navigation pane of the Settings window, select Shared Folders, and then use the add-folder control.
  • Before selecting the shared folder, confirm that the SASUniversityEdition folder and its myfolders subfolder exist at Macbook/SASUniversityEdition/myfolders.
  • In the Add Share window, select Other as the folder path. In the Select Folder window, open SASUniversityEdition and select the myfolders subfolder.
  • Make sure Read-only is not selected if SAS must create or update files in the directory.
  • Select Auto-mount and Make Permanent.
  • Click OK to close the Settings window.

Troubleshooting SAS Studio Accessible-Path Errors

When accessing your data from SAS Studio, you may see an error message similar to the follow ing example:
ERROR: The path /users/xxyyzz/Downloads/Cheatsheet.xlsx is invalid because it is not in the list of accessible paths when SAS is in the lockdown state.
If you see error messages similar to the above examples, you may have shared folders configured incorrectly.

This error means the SAS server process cannot access the specified client-side or host-side path. In the VirtualBox setup, verify that the folder is shared, mounted, writable, and referenced through its SAS-accessible path. In a centrally managed environment, request an approved server path rather than attempting to bypass lockdown restrictions.

Assigning a SAS Library with the LIBNAME Statement

The following program assigns the libref PRASANTH to a directory under /folders/myfolders. Existing compatible SAS datasets in that directory become available through the library, and new datasets created with the PRASANTH libref are written there.

Using the below program, we are creating a library called “Prasanth”. And we specified a location to create prasanth library. So whatever SAS datasets are there in the location will reflect on prasanth library.
Libname prasanth "/folders/myfolders/tutorialkart.com";

Whatever datasets you are creating in front of the dataset use your Libname so that dataset will store into your library and specified location.

Data prasanth.dataset1;
Infile datalines;
input id name$ sex$ age sal;
Datalines;
001 Adarsh M 28 40000
002 Malli M 26 35000
003 Prasanth M 27 30000
;
Run;
  • As shown in above program, prasanth.dataset1 is the name of the table (Dataset).
  • Save the program by selecting the folder as shown below.

SAS program Output Data

How the DATA Step Creates PRASANTH.DATASET1

  1. The LIBNAME statement assigns PRASANTH to the specified physical directory.
  2. The DATA statement names the output dataset as PRASANTH.DATASET1, so it is stored in the assigned permanent library rather than WORK.
  3. The INPUT statement defines five variables. The dollar signs identify NAME and SEX as character variables; the remaining variables are numeric.
  4. The DATALINES statement tells SAS that inline data records follow.
  5. The semicolon after the final record ends the inline data, and the RUN statement submits the DATA step.

After running the program, inspect the SAS log before relying on the output. Confirm that the library was assigned successfully, the expected number of observations and variables were created, and no invalid-data or path errors were reported.

SAS Dataset Naming and Storage Checks

  • Use a valid libref of up to eight characters when assigning a library.
  • Use WORK.member when the result is needed only during the current session.
  • Use libref.member when the result must be written to an assigned permanent location.
  • Confirm that the operating-system or server account running SAS has permission to read and write the target directory.
  • Do not assume that a path visible on your computer is also visible to a remote SAS server.
  • Check the SAS log for an unsuccessful LIBNAME assignment, missing directory, permission problem, or locked dataset.
  • Avoid opening the same dataset for incompatible updates in multiple processes at the same time.

Frequently Asked Questions About SAS Datasets

What is a SAS dataset?

A SAS dataset is a structured SAS file containing observations, variables, and descriptor metadata. A native SAS data file commonly uses the .sas7bdat extension.

What is the difference between WORK.SALES and MYLIB.SALES?

WORK.SALES is temporary and normally disappears when the session ends. MYLIB.SALES is stored through the MYLIB library assignment and can remain available after the session if MYLIB points to persistent storage.

What format does SAS use for datasets?

The native SAS data file format is commonly represented by the .sas7bdat extension. Compatibility can depend on the SAS environment, operating system, encoding, and file attributes. SAS can also access other formats through import facilities and data-access engines.

Are there four standard types of SAS datasets?

There is no single four-type classification that applies in every SAS context. For storage duration, datasets are usually described as temporary or permanent. For SAS member type, a library can contain data members and views. Other classifications may refer to source, structure, or analytical use.

Can SAS be used for ETL?

Yes. SAS programs and SAS data-management products can extract data from supported sources, transform it with DATA steps or procedures, and load the result into SAS datasets or other supported destinations. The available connectors and features depend on the installed SAS products and licenses.

SAS Dataset Tutorial Editorial QA Checklist

  • Verify that temporary output is identified with the WORK library and permanent output uses an assigned persistent library.
  • Confirm that all example librefs and two-level dataset names are used consistently.
  • Check that the VirtualBox instructions are clearly identified as applying to the illustrated SAS University Edition setup.
  • Confirm that the shared folder is writable and that its SAS-visible path matches the LIBNAME statement.
  • Run the sample DATA step and verify that PRASANTH.DATASET1 contains three observations and five variables.
  • Review the SAS log for LIBNAME, path, permission, and invalid-data messages before approving the tutorial output.