/*
--------------------------------------------------------------
File: ~carey/p5741dir/heights.input.sas
Two examples of getting raw data into a sas data set
Example 1: Read the data in from the command stream
--------------------------------------------------------------- */
DATA heights;
/* This DATA statement tells SAS to create a new dataset called
heights1 */
INPUT sex $ height @@
/* This INPUT statement tells SAS to input observations. The
first
variable to be input is sex. The dollar sign after sex tells sas
that
sex is a character string (i.e., not a number). The second
variable
is called height. It is a numeric variable that gives a person's
height in centimeters. The @@ tells SAS to hold the current input
line because there might be another observation on it */
IF sex='f' THEN csex=-1; ELSE csex=1;
/* These are programming statements that tell SAS to create a new
variable
variable called csex. Variable csex will have a value of 1 for males
and
a value of -1 for females. This is called a "contrast code," a topic
that
we will learn a lot about later in the course. */
heightin=height/2.54;
/* Another programming statement. It creates a new variable
called
heightin that gives height in inches */
LABEL
height='Height (cm)'
csex='Sex contrast code'
heightin='Height (in)';
/* The LABEL statement is not necessary but it gives an extended
label to
a variable. Hence, when sas writes output, instead of printing
"height"
it will print "Height (cm)" */
/* the CARDS statements below tells SAS to start reading in the
data */
CARDS;
f 167 f 170 f 169
f 172 f 150 f 164
f 156 f 157 f 155
f 152 f 166 f 165
f 173 f 157 f 168
f 165 f 182 f 163
m 169 m 179 m 185
m 180 m 175 m 189
m 171 m 168 m 183
m 172 m 182 m 182
m 174 m 158 m 171
m 181 m 160 m 195
;
/* It is good practice to end the data stream with a semicolon */
/* The RUN statement below tells sas to execute the above commands
*/
RUN;
/*
-------------------------------------------------------------------
Two examples of getting raw data into a sas data set
Example 2: Read the data in from a text file on the computer
--------------------------------------------------------------------
*/
DATA heights2;
/* Again create a sas dataset, but this time the dataset is
called
heights2 */
INFILE '~carey/p5741dir/datasets/heights.dat';
/* the INFILE statement gives the and pathway and name of the
file
that contain the raw data. In this case the file is called
heights.dat
and it is located on directory ~/carey/p5741dir/datasets */
/* The rest of the statements are the same as those in the
first
example */
INPUT sex $ height @@;
IF sex='f' THEN csex=-1; ELSE csex=1;
heightin=height/2.54;
LABEL
height='Height (cm)'
csex='Sex contrast code'
heightin='Height (in)';
RUN;