举例:
Stkcd year audi1 audi1tenure
000001 1999 A 1
000001 2000 A 2
000001 2001 A 3
000001 2002 B 1
000001 2003 B 2
000001 2004 C 1
000001 2005 A 1
(计算连续审计,虽然A第四次出现,但是不连续,所以2005年A的tenure是1 而不是4)。
我用的程序:
我在网上找的程序,自己改了改,发现大部分结果是对的,但是也有些是错误的。
/*calculate audi1 tenure*/
proc sort data =fin_audit; /* sort the databy firm and year (needed for next data step) */
by stkcd year;
run;
data fin_audit;/* compute tenure; assumingthere is a variable called 'audi1' to identify audi1*/
set fin_audit;
retain audi1tenure prev_audi1; /* willremember the values while processing the rows */
by stkcd;
if first.stkcd then prev_audi = audi1; /*set prev_audi for first record of each stkcd */
if prev_audi1 ne audi1 then audi1tenure = 0;/* audi1 changed: reset tenure */
audi1tenure = audi1tenure + 1;
prev_audi1 = audi1; /* update prev_firm */
run;
请各位大神指教,或者有什么更好的方法,请推荐。谢谢。