SAS: Input/Reading Data
&
Producing Variables,
Summary Statistics
STAT 342 – Fall 2020 Tutorial – 3
• • • •
Objectives
To learn different ways of inputting/reading data with SAS
To learn how to create new variables from the data set
To learn how to produce summary statistics of a data set
To learn how to import comma separated values (CSV) into SAS
Four ways of importing/inputting data depending on the Format of the Data
1. List Input
2. Column Input
3. Formatted Input – an extension to the column input when there are non standard values in the raw data (e.g. $, % etc.)
4. Named Input – when raw data contains variable names within the data set
Input type vs Raw Data Format
Input type Formatted Named
Raw data Contains special characters Variable names provided within the data
Missing data indicated by Blank Blank
Column numbers of Required Required variables
Variable names: Transaction_N0 (numeric), Date, Time, Section (String), Amount ($)
Sample SAS code for Formatted Input
data NAME;
infile ‘path to external data source’; input @1 Var1 character_length.
run;
@5 Var2 $ character_length;
@n: pointer control
moves the input pointer
a specific column number
n
data NAME;
infile ‘path to external data source’; input @1 Var1 character_length.
+1 Var2 $ character_length;
run;
+n: pointer control
moves the input pointer
forward n columns to a
column number that is
relative to the current
position
Sample SAS code for Named Input
data NAME;
infile ‘path to external data source’; input Var1_name= Var2_name= $;
run;
Producing
Variables
& Summary Statistics
Sample SAS code for Creating a New Variable
data NAME;
infile ‘path to external data source’; input Var1$ Var2 Var3;
NewVar = Var3/Var2;
run;
Sample SAS code for Summary Statistics
proc freq NAME; tables Var1;
run;
proc means NAME;
var Var2 Var3 Var4;
run;
Reading a CSV File into SAS
data NAME;
infile ‘path to external data source’ dsd; input Var1$ Var2 Var3;
run;
Delimiter Sensitive Data