SAS - Debugger of DATA step
Introduction
SAS 内置 debug 工具,可以用于 debug DATA step. 通过在 DATA 步中加上相应的 debug 命令,并运行DATA步,就可以调出 Debugger 查看每一行代码的运行结果。
参考DATA Step Debugger: Examples - 9.2 (sas.com)
Usage and Example
首先在 data step 中添加 /debug 命令:
/*This is the raw code*/ data ds2 ; set ds1; by studyid usubjid spid stdtc; retain seq; if first.usubjid then seq=1; else seq=seq+1; seq2=seq; run; /*Add /debug command in the DATA step */ /* /debug 只能加在 data 语句后面,加在其他代码后面是无效的 */ data ds2 /debug; set ds1; by studyid usubjid spid stdtc; retain seq; if first.usubjid then seq=1; else seq=seq+1; seq2=seq; run;
运行代码,自动调出 DEBUGGER LOG 和 DEBUGGER SOURCE 窗口。LOG 窗口展示代码执行情况和结果,并用于输入其他 debug 命令;SOURCE窗口展示 debug 的代码。
通过在LOG窗口每按一次回车,代码就向后执行一行。如果要查看某个变量的值,用命令 examine variable.
examine seq
查看所有变量的值,输入
examine _all_
将代码运行至指定的行并停下,输入
break line_number /* then a ! created at the break line, indicating program running will stop here */
go /* go command execute the whole codes without stopping */
此外,break 语句可以添加条件,使代码运行至指定的条件停下:
break 1143 when stdtc="2018-01" /*stops execution when stdtc is 2018-01*/
终止 Debugger 并退出,输入
quit