G01SASIntroduction(Part1) (1)
G01SASIntroduction(Part1) (1)
Module 1
Dr. Al Schwarzkopf
EXERCISE 1:
Running a program with an internal dataset
DATA FITDATA;
INPUT NAME $ WEIGHT WAIST PULSE CHINS SITUPS JUMPS;
CARDS;
HODGES 191 36 50 5 162 60
KERR 189 37 52 2 110 60
PUTNAM 193 38 58 12 101 101
ROBERTS 162 35 62 12 105 37
BLAKE 189 35 46 13 155 58
ALLEN 182 36 56 4 101 42
HOWARD 211 38 56 8 101 38
VINCENT 167 34 60 6 125 40
STEWART 176 31 74 15 200 40
PERRY 154 33 56 17 251 250
;
PROC SORT DATA=FITDATA;
BY NAME;
RUN;
PROC PRINT• prints data in the DATA= dataset in the order it has been sorted.
There are semi-colons (;) after all the statements, with the exception of the data. You
place a semi-colon at the end of the data only.
The CARDS statement indicates that the lines that follow are data. This statement is
used only for data typed into the code.
The dollar sign in the INPUT statement shows that NAME is a character variable. The
rest of the variables are numeric.
Comment statements can be added to your program by using an asterisk (*) at the
beginning of the statement. Comment statements end with a semi-colon. Comment
statements should be used to properly document your program so that anyone reading
your program can understand what your program is doing.
Indention and blank lines can be used to make your program easy to read and follow.
Some valuable display options are PROC PLOT, PROC CHART, and PROC MEANS.
PROC PLOT - The PLOT procedure graphs one variable against another, producing a
printer plot. The coordinates of each point on the plot correspond to the two variables'
values in one or more observations of the input data set.
You can use PLOT to:
plot character as well as numeric variables
specify the length and width of the plot
reverse the order of the values on the vertical axis
Draw contour plots with shading intensity determined by a third variable in the data
set.
PROC CHART - The CHART procedure produces vertical and horizontal bar charts, block
charts, pie charts, and star charts. These charts are useful for showing pictorially a
variable's values or the relationships between two or more variables.
PROC MEANS - The MEANS procedure produces simple univariate descriptive statistics
for numeric variables.
SAVING DATA IN A SAS LIBRARY
**Reading through the entire Module first will help understand what tasks are being done.
SAS works with data in its own special format called a SAS dataset. You can save data
in this format and avoid the overhead of converting it every time you want to run a
program.
STEP 1: Create a Windows folder to contain the data. You can use any folder, but it is a
good idea to create one especially for the data you are going to use.
STEP 2: Start SAS and go to the Explorer tab to view the “Contents of the SAS
Environment”. (You may have to use the “Up one level” icon to get to this level.)
STEP 4: On the New Library window enter Name (for example FITNESS) up to 8
characters (this will be the working name for the SAS library in your code.) Enter the path
to the Windows folder you have created in Step 1. Press OK.
STEP 5: Add the following SAS code to the program above and run it:
DATA FITNESS.FITDATA2;
SET FITDATA;
RUN;
The SET statement calls the working data set FITDATA that you created in the Data
Step in Exercise 1.
The DATA statement stores that data in the library FITNESS that you just created with
SAS table name of FITDATA2. The Windows name of the new dataset will be
Fitdata1.SAS7BDAT.
STEP 6: To retrieve the data again you can use the code:
DATA FITNESS3;
SET FITNESS.FITDATA2;
You may need to repeat steps 1-4 to connect a new SAS session to the stored library.