SAS: DATALINES Statement

The DATALINES statement in SAS is used to create a dataset. You can input data directly into a SAS program using the DATALINES statement, without the need for an external data file.

Syntax of DATALINES statement

The syntax of DATALINES statement is as follows.

DATA new_dataset;
INPUT variable1 $ variable2 variable3;
DATALINES;
A 10 20
B 15 25
C 8 18
;
RUN;
  1. DATA new_dataset;: This line starts the DATA step and defines a new dataset named new_dataset.
  2. INPUT variable1 $ variable2 variable3;: This line specifies the variable names and their data types. In this case, variable1 is a character variable, while variable2 and variable3 are numeric variables.
  3. DATALINES;: This line indicates the start of the data section.
  4. The lines following DATALINES; represent the data values for each variable. Each line represents one observation, and the values for each variable are separated by spaces.
  5. RUN;: This line marks the end of the DATA step and executes it, creating the "new_dataset" dataset.
A dollar sign $ following a variable name indicates that the variable is a character variable.

Let's print the dataset using PROC PRINT procedure.

proc print data=new_dataset;
run;
SAS: Datalines statement

How to read a large character variable in SAS

By default, the length of a character variable is set at the first occurrence of the variable. If you want to read a large character variable, you can use colon modifier : which tells SAS to read variable until there is a space or other delimiter. The $20. indicates the length of the character variable.

DATA new_dataset;
   INPUT variable1 :$20. variable2 variable3;
   DATALINES;
   Sam 10 20
   MarkSpencers 15 25
   RandyHortonia 8 18
   ;
RUN;

proc print data=new_dataset;
run;
Read a large character variable in SAS
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

0 Response to "SAS: DATALINES Statement"

Post a Comment

Next → ← Prev