Datalines or cards statement


Importing Data for creating SAS Datasets


SAS Data step concepts:

 DATA steps typically create or modify SAS data sets
 Can also be used to produce custom-designed reports.
 SAS DATA steps can be used to:
            put data into a SAS data set
            compute values
            check for and correct errors in your data
            produce new SAS data sets by subsetting, merging, and updating existing data sets.


A SAS data set can be created by:
            Entering data as input
            Reading existing raw data
           Accessing external files (files that were created by other software)


Reading Instream Data using Cards and Datalines
 Data can be entered into SAS data set directly through SAS program
 Reading instream data is useful when to create data and test programming statements on a few
observations
       To read instream data use:
                DATALINES statement as the last statement in the DATA step (except for the RUN
                statement) and immediately preceding the data lines
               a null statement (a single semicolon) to indicate the end of the input data
 Only one DATALINES statement can be used in a DATA step
 Use separate DATA steps to enter multiple sets of data
 If the data contains semicolons, use the DATALINES4 statement plus a null statement that
consists of four semicolons (;;;;) to indicate the end of the input data



Syntax:
DATA <datasetname>;
INPUT <variablename1>[$] <variablename2>[$] … ;
DATALINES;
.
.
data lines go here
.
.
;
run ;
 After the DATALINES statement specify the data values
 After typing in the values give a semicolon to indicate the end of the data values.
 Can also use Cards instead of datalines





Example:
Data emp_details ;
Input id name$ age ;
Datalines ;
2458 Murray, W 42
2462 Almers, C 38
2501 Bonaventure, T 48
2523 Johnson, R 39
2539 LaMance, K 45
2544 Jones, M 49
;
run ;


Here,
 A dataset called emp_details is created with variables id, name & age, and having 6
observations
 Name is a character variable which is indicated by $ sign after name


Note :- we can also use cards statement at the place of datalines 


Data emp_details ;
Input id name$ age ;
Cards ;
2458 Murray, W 42
2462 Almers, C 38
2501 Bonaventure, T 48
2523 Johnson, R 39
2539 LaMance, K 45
2544 Jones, M 49
;
run ;