Sas Data Statement Syntax

Basic format

The first line of the data statement is:
data data-set-name;
Where data-set-name is any alphanumeric string starting with a character and consisting of up to eight characters and ending in a semicolon. For example, to create a temporary dataset named test I would use:

data test;

Creating a permanent data set

The above creates a temporary data set. This means that once your sas program finishes your SAS dataset named test will not exist on the system. Often this makes perfect sense; however in some instances you will find that you can achieve some benefit by saving the data set you create as a permanent file on the system. To do this you must do the following:

libname mylib ".";
data mylib.test;

The first line starting with libname specifies which directory to use when saving the dataset. The value within quotes could be any valid directory name. The second statement informs SAS to create a dataset named test in that directory. After running the SAS program you will have a file created named test.ssd.

Reading a permanent dataset into a new dataset name

If you are reading a file saved as a SAS data set then you use the format:
data libname.dataset;
Where libname is a name associated with a directory in which the dataset can be found; and dataset is the file name of the SAS dataset in that directory which you want to read. For example, if you had a sas dataset named test.ssd in your current working directory you would use the following SAS statements

libname mylib "."
data test; set mylib.test1;

The first statement libname mylib "." associates the name mylib with your current working directory (under Unix this is defined using the period). The second statement creates a SAS dataset named TEST. The third statement reads in the data from the sas data set named test1.ssd in my current working directory.


Author - Jack Suess
Created - 1/15/96