This example shows how to debug a program when you use format statements
to format dates. The following program creates a report that lists
travel tour dates for specific countries.
data tours;
length Country $ 10;
input Country $10. Start : mmddyy. End : mmddyy.;
Duration=end-start;
datalines;
Italy 033012 041312
Brazil 021912 022812
Japan 052212 061512
Venezuela 110312 11801
Australia 122112 011513
;
proc print data=tours;
format start end date9.;
title 'Tour Duration';
run;
The value of Duration
for the tour to Venezuela shows a negative number, -290 days. To help
identify the error, run the DATA step again using the DATA step debugger.
SAS displays the following debugger windows:
At the DEBUGGER LOG
command line, issue the EXAMINE command to display the values of all
variables in the program data vector before execution begins:
examine _all_
Initial values of all
variables appear in the DEBUGGER LOG window. SAS has not yet executed
the INPUT statement.
Press ENTER to issue
the STEP command. SAS executes the INPUT statement, and the assignment
statement is now highlighted.
Issue the EXAMINE command
to display the current value of all variables:
examine _all_
The following display
shows the results:
Because a problem exists
with the Venezuela tour, suspend execution before the assignment statement
when the value of Country equals Venezuela. Set a breakpoint to do
this:
break 4 when country='Venezuela'
Execute the GO command
to resume program execution:
go
SAS stops execution
when the country name is Venezuela. You can examine Start and End
tour dates for the Venezuela trip. Because the assignment statement
is highlighted (indicating that SAS has not yet executed that statement),
there will be no value for Duration.
Execute the EXAMINE
command to view the value of the variables after execution:
examine _all_
The following display
shows the results:
To view formatted SAS
dates, issue the EXAMINE command using the DATEw. format:
examine start date7. end date7.
The following display
shows the results:
Because the tour ends
on November 18, 20120, and not on January 18, 2012, there is an error
in the variable End. Examine the source data in the program and notice
that the value for End has a typographical error. By using the SET
command, you can temporarily set the value of End to November 18 to
see whether you get the anticipated result. Issue the SET command
using the DDMMMYY
w. format:
set end='18nov00'd
Press ENTER to issue
the STEP command and execute the assignment statement.
Issue the EXAMINE command
to view the tour date and Duration fields:
examine start date7. end date7. duration
The following display
shows the results:
The Start, End, and
Duration fields contain correct data.
End the debugging session
by issuing the QUIT command on the DEBUGGER LOG command line. Correct
the original data in the SAS program, delete the DEBUG option, and
resubmit the program.
/* corrected version */
data tours;
length Country $ 10;
input Country $10. Start : mmddyy. End : mmddyy.;
duration=end-start;
datalines;
Italy 033012 041312
Brazil 021912 022812
Japan 052212 061512
Venezuela 110312 111812
Australia 122112 011513
;
proc print data=tours;
format start end date9.;
title 'Tour Duration';
run;