Published on :
ETL CREATION_INTERNE

Creating and Displaying Student Data

This code is also available in: Deutsch Español Français
Awaiting validation
The script repeatedly creates a dataset named 'student'. Initially, a DATA step reads data from 'datalines', attempting to process multiple records on a single physical line. A second DATA step overwrites the previous dataset, including a potentially erroneous line in the INPUT statement and providing in-line data, with one line containing multiple records and another with a single one. Then, a PROC PRINT procedure is used to display the current content of the 'student' dataset. Finally, a third DATA step recreates the 'student' dataset, explicitly specifying the lengths of the character variables 'std_id' and 'gender', then reads two distinct records from 'datalines'.
Data Analysis

Type : CREATION_INTERNE


The data used in this script is entirely integrated and internally defined via the `datalines` statement in each `DATA` step. No external data sources (files, databases) or SAS libraries other than implicit system libraries are requested.

1 Code Block
DATA STEP Data
Explanation :
Creates the 'student' dataset. It attempts to read comma-delimited data from the `datalines` statement. Variables `std_id`, `name`, `gender` (character), `age`, `height`, `weight` (numeric) are defined. The absence of specific options for reading multiple records per line can lead to incomplete data line reading.
Copied!
1DATA student;
2 INFILE DATALINES dlm=",";
3 INPUT
4 std_id $
5 name $
6 gender $
7 age
8 height
9 weight
10 ;
11 DATALINES;
12101,ABC,F,23,167,76,102,DEF,M,25,176,87
13 ;
14RUN;
2 Code Block
DATA STEP Data
Explanation :
This DATA step recreates the 'student' dataset, overwriting the previous version. It uses `infile datalines` for input. The line ` @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json` in the `input` statement is a syntax error that will not be correctly interpreted by SAS as an input option. Two data lines are provided, the first potentially creating a partial record due to reading without ` @@`, and the second providing a complete record.
Copied!
1DATA student;
2 INFILE DATALINES dlm="," ;
3 INPUT
4 std_id $
5 name $
6 gender $
7 age
8 height
9 weight
10 @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json
11 ;
12 DATALINES;
13101,ABC,F,23,167,76,102,DEF,M,25,176,87
14103,GHI,M,25,176,87
15 ;
16RUN;
3 Code Block
PROC PRINT
Explanation :
Executes the `PROC PRINT` procedure to display the entire content of the 'student' dataset in the output window. This is a standard method for inspecting data.
Copied!
1PROC PRINT DATA=student;
2RUN;
4 Code Block
DATA STEP Data
Explanation :
This final DATA step once again recreates the 'student' dataset. It uses `length` statements to explicitly define the length of character variables `std_id` (3 characters) and `gender` (1 character) before the data is read. Two complete records are read from distinct `datalines`.
Copied!
1DATA student;
2 LENGTH std_id $3. gender $1.;
3 INFILE DATALINES dlm=",";
4 INPUT
5 std_id $
6 name $
7 gender $
8 age
9 height
10 weight
11 ;
12 DATALINES;
13101,ABC,F,23,167,76
14102,DEF,M,25,176,87
15 ;
16RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.