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;
DATA new_dataset;
: This line starts theDATA
step and defines a new dataset namednew_dataset
.INPUT variable1 $ variable2 variable3;
: This line specifies the variable names and their data types. In this case,variable1
is a character variable, whilevariable2
andvariable3
are numeric variables.DATALINES;
: This line indicates the start of the data section.- 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. RUN;
: This line marks the end of theDATA
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;
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;
Share Share Tweet