When you create a SAS data set using the datalines statement, SAS supposes that each variable is separate by a blank space. However, some variables contain spaces or are separated by another character. In this case, you need the SAS delimiter statement.
Suppose you want to create a data set with two columns; Name and Age. The variables are separated by a comma. Besides that, the name variable might contain a space, e.g. “Maria Jose” or “Juan Antonio”. To correctly process the input data, you need to use a delimiter statement. The example below shows how to use the delimiter statement for comma-separated data.
data work.ds;
/* Define the Delimiter */
infile datalines delimiter=',';
/* Define the Length of the Variables */
length Name $ 12;
/* Define the Variable Names */
input Name $ Age;
/* Define the Content of the Data Set */
datalines;
Maria Jose, 30
Juan Antonio, 32
;
run;
The delimiter statement is essential to read CSV-files. However, some input files are separated by a tab. So, to correctly process these files you need to use delimiter=”09″x.
If you just want to create a simple, non delimited data set, check out this example.
You can find the official SAS documentation of the delimiter statement here.
3 thoughts on “Create a SAS Data Set with the Delimiter statement”
Comments are closed.