0% found this document useful (0 votes)
3 views

stat 440 lab exercises 1

The document provides instructions for completing lab exercises in Statistics 440, focusing on using the SAS software environment. It covers starting a SAS session, navigating the interface, debugging SAS programs, and correcting common errors such as unbalanced quotes. The exercises guide users through submitting programs, examining output, and saving their work effectively.

Uploaded by

newtondr7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

stat 440 lab exercises 1

The document provides instructions for completing lab exercises in Statistics 440, focusing on using the SAS software environment. It covers starting a SAS session, navigating the interface, debugging SAS programs, and correcting common errors such as unbalanced quotes. The exercises guide users through submitting programs, examining output, and saving their work effectively.

Uploaded by

newtondr7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Statistics 440: Lab Exercises 1

Before you begin:


Login to Illinois Compass (compass.uiuc.edu) and download all of the files from
Data/Lab 1 folder. Move the files to the folder you use for the class files (e.g D:\netid).

Exercise 1: Exploring Your SAS Environment under Windows


Starting a SAS Session
1. From the Start menu, select Programs > SAS > SAS 9.2 (English).
How you invoke SAS varies by your operating environment and any customizations in effect
at your site.

2. Open the file lab1ex1.sas either by selecting File  Open, or by clicking on .

Enhanced Editor
The Enhanced Editor (the default editor on Windows) provides many helpful features, including
color coding and automatically retaining the program after each submit, eliminating the need to
recall your program.
In the Enhanced Editor, each program you open will open a new Enhanced Editor. You can have
numerous Enhanced Editors open at one time. However, if you are using the Program Editor, you
can only have one Program Editor open at a time.
 The Enhanced Editor is available only on Windows.

 The program contains three steps: a DATA step and two PROC steps.
As you browse the program, notice the following:
• The syntax is color-coded to show
– step boundaries
– keywords
– variable and data set names.
• A section boundary line separates each step.

1
Statistics 440: Lab Exercises 1

With the Enhanced Editor, you have the ability to minimize and maximize each DATA or
PROC step. A minus sign next to DATA or PROC indicates that the code has been
expanded. To minimize the DATA or PROC step, click on the minus sign. Once the step
has been minimized, the minus sign turns into a plus sign . To maximize the step after
it has been minimized, click on the plus sign.

 You can customize the appearance and functionality of the Enhanced Editor by selecting
Tools  Options  Enhanced Editor.

3. Issue the SUBMIT command or click on or select Run  Submit to submit the
program for execution. The output from the program is displayed in the Output window.
 You can submit the code when it is collapsed. This is helpful if you want to highlight a
portion of the program and submit only that portion. You can highlight the entire line that
is visible for a step and submit it. To highlight the entire line, click to the left of the plus
sign .

Navigating in Your SAS Session


• The Results and Output windows are displayed when you submit a program that generates
output.
• You can use the Ctrl and Tab keys to navigate between windows.
• You can use the SAS window bar at the bottom of the workspace to navigate between all
of the windows in the SAS windowing environment or to minimize and maximize
windows.
• Each window in the workspace has its own menu selections that reflect
the actions you can perform when that window is active. This applies to
pull-down, pop-up, and tool bar menus.
• The Results window lists all the reports that appear in the Output window. You can
double-click and drill down on each procedure in the Results window, which enables you
to go to that report in the Output window.
• Starting in Version 8, you can also use the Results window to erase particular reports from
the Output window. You can delete each individual report by either right-clicking on the
output name and selecting Delete or clicking on the on the tool bar.

______________________________________________________________________________
Portions Copyright  2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.
Reproduced with permission of SAS Institute Inc., Cary, NC, USA. SAS Institute Inc. makes no
warranties with respect to these materials and disclaims all liabilities thereof.

2
Statistics 440: Lab Exercises 1

Examining Your Program Results


The Output window
• is one of the primary windows and is open by default.
• becomes the active window each time it receives output.
• automatically accumulates output in the order in which it is generated. You can issue the
CLEAR command or select Edit  Clear All to clear the contents of the
window, or you can click on the NEW icon .
To scroll horizontally within the Output window, use the horizontal scrollbar or issue the RIGHT
and LEFT commands.
In the Windows environment, the Output window displays the last page of output generated by
the program submitted.

To scroll vertically within the Output window, use the vertical scrollbar or issue the FORWARD
and BACKWARD commands or use the PAGE UP or PAGE DOWN keys on the keyboard.
 You also can use the TOP and BOTTOM commands to scroll vertically within the Output
window.
1. Scroll to the top to view the output from the PRINT procedure.

2. Issue the LOG command or select Window  Log or click on the log to display the Log
window and browse the messages that the program generated.

3
Statistics 440: Lab Exercises 1

The Log window


• is one of the primary windows and is open by default.
• acts as an audit trail of your SAS session; messages are written to the log in the order in
which they are generated by the program.
3. To clear the contents of the window, issue the CLEAR command, select
Edit  Clear All, or click on the NEW icon .

Partial Log

The Log window contains the programming statements that are submitted, as well as notes
about
• any files that were read
• the records that were read
• the program execution and results.
In this example, the Log window contains no warning or error messages. If the program
contains errors, relevant warning and error messages are also written to the SAS log.
4. Issue the END command or select Window  Program Editor to return to the Program
Editor window.

4
Statistics 440: Lab Exercises 1

Exercise 2: Debugging a SAS Program


Submit a SAS Program with Errors
1. Open the file lab1ex2a.sas and submit the program.
Examine the SAS log. It should contain error messages and warnings.
1 daat work.staff;
----
14
WARNING 14-169: Assuming the symbol DATA was misspelled as daat.

2 infile 'raw-data-file';
3 input LastName $ 1-20 FirstName $ 21-30
4 JobTitle $ 36-43 Salary 54-59;
5 run;

NOTE: The infile 'raw-data-file' is:


File Name='raw-data-file',
RECFM=V,LRECL=256

NOTE: 18 records were read from the infile 'raw-data-file'.


The minimum record length was 59.
The maximum record length was 59.
NOTE: The data set WORK.STAFF has 18 observations and 4
variables.
NOTE: DATA statement used (Total process time):
real time 0.08 seconds
cpu time 0.07 seconds

6
7 proc print data=work.staff
8 run;
---
22
-
200
ERROR 22-322: Syntax error, expecting one of the following: ;,
(, DATA, DOUBLE, HEADING, LABEL, N, NOOBS, OBS,
ROUND, ROWS, SPLIT, STYLE, UNIFORM, WIDTH.
ERROR 200-322: The symbol is not recognized and will be ignored.
9

NOTE: The SAS System stopped processing this step because of


errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.06 seconds
cpu time 0.06 seconds

10 proc means data=work.staff average max;


------- ---
22 202
ERROR 22-322: Syntax error, expecting one of the following: ;,

5
Statistics 440: Lab Exercises 1

(, ALPHA, CHARTYPE, CLASSDATA, CLM,


COMPLETETYPES, CSS, CV, DATA, DESCEND,
DESCENDING, DESCENDTYPES, EXCLNPWGT, EXCLNPWGTS,
EXCLUSIVE, FW, IDMIN, KURTOSIS, LCLM, MAX,
MAXDEC, MEAN, MEDIAN, MIN, MISSING, N, NDEC,
NMISS, NONOBS, NOPRINT, NOTHREADS, NOTRAP, NWAY,
ORDER, P1, P10, P25, P5, P50, P75, P90, P95, P99,
PCTLDEF, PRINT, PRINTALL, PRINTALLTYPES, PRINTIDS,
PRINTIDVARS, PROBT, Q1, Q3, QMARKERS, QMETHOD,
QNTLDEF, QRANGE, RANGE, SKEWNESS, STDDEV,
STDERR, SUM, SUMSIZE, SUMWGT, T, THREADS, UCLM,
USS, VAR, VARDEF.
ERROR 202-322: The option or parameter is not recognized and
will be ignored.
11 class JobTitle;
12 var Salary;
13 run;

NOTE: The SAS System stopped processing this step because of


errors.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.05 seconds
cpu time 0.05 seconds

Debugging Your Program


The log indicates that SAS
• assumed the keyword DATA was misspelled and executed the DATA step
• interpreted the word RUN as an option in the PROC PRINT statement (because there was a
missing semicolon), so PROC PRINT was not executed
• did not recognize the word AVERAGE as a valid option in the PROC MEANS statement, so
the PROC MEANS step was not executed.
2. Edit the program.
a. Correct the spelling of DATA.
b. Put a semicolon at the end of the PROC PRINT statement.
c. Change the word AVERAGE to MEAN in the PROC MEANS statement.
data work.staff;
infile 'D:\Stat 440\emplist.dat';
input LastName $ 1-20 FirstName $ 21-30
JobTitle $ 36-43 Salary 54-59;
run;

proc print data=work.staff;


run;

proc means data=work.staff mean max;


class JobTitle;
var Salary;
run;
3. Submit the program. It runs successfully without errors and generates output.

6
Statistics 440: Lab Exercises 1

Saving Your Program


You can use the FILE command to save your program to a file. The program must be in the
Enhanced Editor or Program Editor before you issue the FILE command. If the code is not in the
Program Editor, recall your program before saving the program.
You can also select File  Save As.
A note appears that indicates the statements are saved to the file.

Submitting a SAS Program That Contains Unbalanced Quotes


The closing quote for the INFILE statement is missing.
4. Open the file lab1ex2b.sas and submit the program. Browse the SAS log.

There are no notes in the SAS log because all of the SAS statements after the INFILE statement
have become part of the quoted string.
 The banner on the window indicates the DATA step is still running because the RUN
statement was not recognized.

Point-and-Click Approaches to Balancing Quotation Marks

1. To correct the problem in the Windows environment, click the break icon or press the
Ctrl and Break keys.
2. Select 1. Cancel Submitted Statements in the Tasking Manager window and select OK.

7
Statistics 440: Lab Exercises 1

3. Select Y to cancel submitted statements,  OK.

Correcting Unbalanced Quotes Programatically


You can correct the unbalanced quotes programmatically by adding the following code before
your previous statements:
*';*";run;
If the quote counter within SAS has an uneven number of quotation marks as seen in the above
program, SAS reads the quotation in the comment above as the matching quote in the quote
counter. SAS then has an even number of quotes in the quote counter and runs successfully,
assuming no other errors occur. Both single quotation marks and double quotation marks are used
in case you submitted double quotation marks instead of single quotation marks.

Resubmitting the Program


1. Add a closing quote (’) to the file reference on the INFILE statement.
2. Resubmit the program.
Partial SAS Log
27 data work.staff;
28 infile 'raw-data-file';
29 input LastName $ 1-20 FirstName $ 21-30
30 JobTitle $ 36-43 Salary 54-59;
31 run;

NOTE: 18 records were read from the infile 'raw-data-file'.


The minimum record length was 59.
The maximum record length was 59.
NOTE: The data set WORK.STAFF has 18 observations and 4 variables.
32
33 proc print data=work.staff;
34 run;

NOTE: There were 18 observations read from the dataset WORK.STAFF.


35
36 proc means data=work.staff mean max;
37 class JobTitle;
38 var Salary;
39 run;
NOTE: There were 18 observations read from the dataset WORK.STAFF.

You might also like