如何使用 PROC EXPAND 填充面板(纵向)数据集中的时间序列观察值?
How do I use PROC EXPAND to fill in time series observations within a panel (longitudinal) data set?
我正在使用这个 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 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
的输出只是说 "Nothing to do. The data set WORK.TEST3 has 0 observations and 0 variables." 我不 want/need 改变数据的频率,只是用缺失值插入它。
我在这里做错了什么?我认为 proc expand
是基于 this example and the documentation 的正确使用过程,但无论出于何种原因,它都不会创建数据。
您需要添加 VAR
语句。不幸的是,变量必须是数字。所以只需将 month
扩展 cust_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;
我正在使用这个 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 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
的输出只是说 "Nothing to do. The data set WORK.TEST3 has 0 observations and 0 variables." 我不 want/need 改变数据的频率,只是用缺失值插入它。
我在这里做错了什么?我认为 proc expand
是基于 this example and the documentation 的正确使用过程,但无论出于何种原因,它都不会创建数据。
您需要添加 VAR
语句。不幸的是,变量必须是数字。所以只需将 month
扩展 cust_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;