SAS: Cards and Data lines statments

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.

SAS CARDS Statement: Learn with Examples

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

The CARDS statement is an alternative to the DATALINES statement and serves the same purpose. It is used in the same way as DATALINES to specify inline data within the SAS program.

Syntax of CARDS statement

The syntax of CARDS statement is as follows.

DATA new_dataset;
INPUT variable1 $ variable2 variable3;
CARDS;
A 10 20
B 15 25
C 8 18
;
RUN;

RUN;: marks the end of the DATA step and executes it, creating the “new_dataset” dataset.

DATA new_dataset;: Starts the DATA step and defines a new dataset named new_dataset.

INPUT variable1 $ variable2 variable3;: Specifies the variable names and their data types. In this case, variable1 is a character variable, while variable2 and variable3 are numeric variables.

CARDS;: Indicates the start of the data section.

The lines following CARDS; are the data values for each variable. Each line represents one observation, and the values for each variable are separated by spaces.