全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1496 1
2015-03-04

举例:

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第四次出现,但是不连续,所以2005Atenure1 而不是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;

请各位大神指教,或者有什么更好的方法,请推荐。谢谢。


附件列表
1.jpg

原图尺寸 80.65 KB

1.jpg

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-3-4 19:27:46
data m;
input stkcd$ year auditor$;
cards;
000001 1999 A
000001 2000 A
000001 2001 A
000001 2002 B
000001 2003 B
000001 2004 C
000001 2005 A
;
proc sort data=m;
by stkcd year auditor;
run;
data m;
set m;
if auditor='A' then x=1;
if auditor='B' then x=2;
if auditor='C' then x=3;
y=lag(x);
run;
data m;
set m;
if x-y ne 0 then n=0;
n+1;
drop x y;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群