本文介绍了按组折叠非缺失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Name Apr14 May14 Jun14 Aug14
John R
Peter G
Peter G
Peter G
Louis R
Louis G
Carl R
Dany R
Dany G
我需要唯一值,但不要像这样丢失值.
I need unique values but keep the values not missing like this.
Name Apr14 May14 Jun14 Aug14
John R
Peter G G G
Louis R G
Carl R
Dany R G
我该怎么做?
推荐答案
最简单的方法是更新语句.它只用非缺失值更新缺失值.我们用 (obs=0) 初始化它,因为基本"数据集在这里实际上并不相关 - 我们只是用它来折叠事物.
Easiest way to do this is the update statement. It only updates missing values with nonmissing. We initialize it with (obs=0) since the 'base' dataset isn't actually relevant here - we're just using this to collapse things.
data have;
infile datalines truncover;
input (Name Apr14 May14 Jun14 Aug14) ($);
datalines;
John R
Peter G
Peter . G
Peter . . G
Louis . . R
Louis . . . G
Carl . . R
Dany R
Dany . . G
;;;;
run;
proc sort data=have;
by name;
run;
data want;
update have(obs=0) have;
by name;
run;
这篇关于按组折叠非缺失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!