youthy
要合并两个SPSS数据文件,第1个文件含有重复关键变量,第2个没有,用合并变量的功能时提示要排序什么的,最后的OUTPUT显示了一些大概是错误的信息,反正是没有合并成功。所以,如何才能做成功?
举个简化的实例:
第1个文件有2个变量:
1 5
1 6
1 7
2 8
2 9
2 10
3 11
3 12
3 13
第2个文件有2个变量:
1 35
2 36
3 37
想要合并为下列排列形式的数据文件:
1 5 35
1 6 35
1 7 35
2 8 36
2 9 36
2 10 36
3 11 37
3 12 37
3 13 37
请教如何操作?
怎么可能
data a1;
input x y@@;
cards;
1 5
1 6
1 7
2 8
2 9
2 10
3 11
3 12
3 13
;
proc sort;
by x;
run;
data a2;
input x z@@;
cards;
1 35
2 36
3 37
;
proc sort;
by x;
run;
data aa;
merge a2 a1;
by x;
run;
proc print;
run;
youthy
看不懂。。。。。具体是怎么回事总要说下吧?
怎么可能
发错地方了,这是SPSS版
youthy
晕。。。。。。。
fairy
可以根据key变量横向合并的,不会报错,只是合并后没有重复主键的数据集中除主键以外的变量有很多缺失值,可以在compute中编写表达式填充,以下是我的试验:
*生成含重复主键模拟待合并数据集并保存.
data list free /id amt.
begin data
1 5
1 6
1 7
2 8
2 9
2 10
3 11
3 12
3 13
end data.
save outfile='C:\Documents and Settings\fairy\桌面\exch.sav'
/compressed.
*生成不含重复主键模拟待合并数据集并保存.
data list free /id age.
begin data
1 35
2 36
3 37
end data.
save outfile='C:\Documents and Settings\fairy\桌面\cust.sav'
/compressed.
*根据主键横向合并数据集.
match files /file='C:\Documents and Settings\fairy\桌面\cust.sav'
/file='C:\Documents and Settings\fairy\桌面\exch.sav'
/by id.
save outfile='C:\Documents and Settings\fairy\桌面\cust_exch.sav'
/compressed.
execute.
*填补年龄缺失值并保存数据文件.
loop if missing(age).
compute age=lag1(age).
end loop if(id ~=lag1(id)).
save outfile='C:\Documents and Settings\fairy\桌面\cust_exch.sav'
/compressed.
execute.
youthy
fairy应该是做得不错。但关键是,我刚学啊,我不知道什么是compute!!!!!!
所以,,,,,,我不知道怎么操作。。。。。。
youthy
不要用编程!用菜单操作好不好?因为实际上要处理的数据有几万条啊!我不可能一条条录进去的!
youthy
而且,我用菜单操作时,就是报错!
youthy
用菜单操作成功!正在分析原来出错的原因。。。。。。
youthy
使用了升序排序后成功的。可能是这方面原因。
zhch
菜单怎么操作,谢谢!
急用!!
zhch
终于知道怎么弄了
合并时要将两个文件的关键变量排序(输入时看似排好了,也要重新排一次),再选择Match cases on key variables in sorted filesm的第二项external-----,就全出来了,没有缺失的。
zhch
如果选Match cases on key variables in sorted filesm的第一项both-----就有缺失的,要补上