Sas 如何使用PROC EXPAND在面板(纵向)数据集中填写时间序列观测值?
我正在使用此SAS代码:Sas 如何使用PROC EXPAND在面板(纵向)数据集中填写时间序列观测值?,sas,Sas,我正在使用此SAS代码: data test1; input cust_id $ month category $ status $; datalines; A 200003 ABC C A 200004 DEF C A 200006 XYZ 3 B 199910 ASD X B 199912 ASD C ; quit; proc sql; create view test2 as select cus
data test1;
input cust_id $
month
category $
status $;
datalines;
A 200003 ABC C
A 200004 DEF C
A 200006 XYZ 3
B 199910 ASD X
B 199912 ASD C
;
quit;
proc sql;
create view test2 as
select cust_id, input(put(month, 6.), yymmn6.) as month format date9.,
category, status from test1 order by cust_id, month asc;
quit;
proc expand data=test2 out=test3 to=month method=none;
by cust_id;
id month;
quit;
proc print data=test3;
title "after expand";
quit;
我想创建一个如下所示的数据集:
Obs cust_id month category status
1 A 01MAR2000 ABC C
2 A 01APR2000 DEF C
3 A 01MAY2000 . .
4 A 01JUN2000 XYZ 3
5 B 01OCT1999 ASD X
6 B 01NOV1999 . .
7 B 01DEC1999 ASD C
但是proc expand
的输出只是说“没什么可做的。数据集WORK.TEST3有0个观察值和0个变量。”我不想/需要更改数据的频率,只要用缺失的值对其进行插值即可
我做错了什么?我认为
proc expand
是使用的正确过程,基于和,但无论出于何种原因,它都不会创建数据 您需要添加一个VAR
语句。不幸的是,变量必须是数字。因此,只需通过cust\u id
扩展月份
。然后连接回原始值
proc expand data=test2 out=test3 to=month ;
by cust_id;
id month;
var _numeric_;
quit;
proc sql noprint;
create table test4 as
select a.*,
b.category,
b.status
from test3 as a
left join
test2 as b
on a.cust_id = b.cust_id
and a.month = b.month;
quit;
proc print data=test4;
title "after expand";
quit;