由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 关于recode data的问题,多谢。
相关主题
SAS help needed!包子问,SAS里data long to wide format
新手问个简单的sas问题hi, an interview question
sas里怎么取相邻2个observation的差?请问sas中一个变量的内容被两个左斜杠(/)分成了三部分
一个已经问过的问题(出现新情况),多谢!如何证明数据是伪造的?
SAS 问题求助,有包子请教一个SAS问题
help for sas program[合集] 自问自答刚才问的问题,但请各位帮我简化下code
如何把一个variable中missing 的observation 付上非missing observation 的valuehow to assign the value of prevoius observation to?
SAS question (紧急求助,在线等)help! SAS base 70 problem 17/35
相关话题的讨论汇总
话题: a5话题: a1话题: data话题: a2话题: a4
进入Statistics版参与讨论
1 (共1页)
l**********s
发帖数: 255
1
有以下的一组数据data one(真实数据有上百个变量和上千个observation,用data
one做例子为了能方便描述自己的问题),如果一个observation从a1到a5的所有值都是
0,想把他成".",最后得到如同data two的数据。
我现在想到的方法有二种,方法一就是先把所有从a1到a5的observation的ID找出来,
然后根据ID来recode data。这样虽然可以达到目的,但是比较笨,而且在找id的过程中
容易出错。
方法一的code在后面。
方法二就是用"if ....then...",把符合条件,也就是a1=0 and a2=0 and a3=0 and
a4=0 and a5=0的observations从"0"成".",但是好像我的code不成功,不知道那位能
帮我找出为什么。
而且就算我的方法二没有问题,因为实际数据很大,code也会很长,是不是要用macro
或array?哪位高人能指点下?多谢多谢!
data one;
input ID a1 a2 a3 a4 a5;
datalies;
1 0 0 0 0 0
2 0 0 0 0 0
3 0
s******r
发帖数: 1524
2
data one;
input ID a1 a2 a3 a4 a5;
datalines;
1 0 0 0 0 0
2 0 0 0 0 0
3 0 1 1 0 0
;
run;
data test(keep=id) two;
set one;
if max(of a1-a5)=0 and min(of a1-a5)=0 then output test;
else output two;run;
data two;set test two ;run;

【在 l**********s 的大作中提到】
: 有以下的一组数据data one(真实数据有上百个变量和上千个observation,用data
: one做例子为了能方便描述自己的问题),如果一个observation从a1到a5的所有值都是
: 0,想把他成".",最后得到如同data two的数据。
: 我现在想到的方法有二种,方法一就是先把所有从a1到a5的observation的ID找出来,
: 然后根据ID来recode data。这样虽然可以达到目的,但是比较笨,而且在找id的过程中
: 容易出错。
: 方法一的code在后面。
: 方法二就是用"if ....then...",把符合条件,也就是a1=0 and a2=0 and a3=0 and
: a4=0 and a5=0的observations从"0"成".",但是好像我的code不成功,不知道那位能
: 帮我找出为什么。

D******n
发帖数: 2836
3
omg...

【在 l**********s 的大作中提到】
: 有以下的一组数据data one(真实数据有上百个变量和上千个observation,用data
: one做例子为了能方便描述自己的问题),如果一个observation从a1到a5的所有值都是
: 0,想把他成".",最后得到如同data two的数据。
: 我现在想到的方法有二种,方法一就是先把所有从a1到a5的observation的ID找出来,
: 然后根据ID来recode data。这样虽然可以达到目的,但是比较笨,而且在找id的过程中
: 容易出错。
: 方法一的code在后面。
: 方法二就是用"if ....then...",把符合条件,也就是a1=0 and a2=0 and a3=0 and
: a4=0 and a5=0的observations从"0"成".",但是好像我的code不成功,不知道那位能
: 帮我找出为什么。

l**********s
发帖数: 255
4
Thanks a lot! It works!!

【在 s******r 的大作中提到】
: data one;
: input ID a1 a2 a3 a4 a5;
: datalines;
: 1 0 0 0 0 0
: 2 0 0 0 0 0
: 3 0 1 1 0 0
: ;
: run;
: data test(keep=id) two;
: set one;

l**********s
发帖数: 255
5
再请问下,如果我的数据实际上变量很多,只需要处理其中的个5变量a1-a5,按照楼上
的指导确实可以做到,但是要
多合并一次文件,其他变量保持不变, 请问如果有没有办法用macro 或者array做呢?
多谢。
data one;
input ID a1 a2 a3 a4 a5 abc cnn nb;
datalines;
1 0 0 0 0 0 5 6 7
2 0 0 0 0 0 7 4 9
3 0 1 1 0 0 4 4 4
;
run;
data two;
input ID a1 a2 a3 a4 a5 abc cnn nb;
datalines;
1 . . . . . 5 6 7
2 . . . . . 7 4 9
3 0 1 1 0 0 4 4 4
;
run;
s******r
发帖数: 1524
6
update
keep=id
as
drop=a1-a5

【在 l**********s 的大作中提到】
: 再请问下,如果我的数据实际上变量很多,只需要处理其中的个5变量a1-a5,按照楼上
: 的指导确实可以做到,但是要
: 多合并一次文件,其他变量保持不变, 请问如果有没有办法用macro 或者array做呢?
: 多谢。
: data one;
: input ID a1 a2 a3 a4 a5 abc cnn nb;
: datalines;
: 1 0 0 0 0 0 5 6 7
: 2 0 0 0 0 0 7 4 9
: 3 0 1 1 0 0 4 4 4

y****n
发帖数: 46
7
data one;
array aa(5) a1-a5;
input ID a1 a2 a3 a4 a5 abc cnn nb;
do i=1 to 5;
if aa(i)=0 then aa(i)=.;
end;
drop i;
datalines;
1 0 0 0 0 0 5 6 7
2 0 0 0 0 0 7 4 9
3 0 1 1 0 0 4 4 4
;
run;
y****n
发帖数: 46
8
data one;
array aa(5) a1-a5;
input ID a1 a2 a3 a4 a5 abc cnn nb;
if sum(of a1-a5)=0 then do;
do i=1 to 5;
if aa(i)=0 then aa(i)=.;
end;
end;
drop i;
datalines;
1 0 0 0 0 0 5 6 7
2 0 0 0 0 0 7 4 9
3 0 1 1 0 0 4 4 4
;
run;
l**********s
发帖数: 255
9
Thanks! It works!

【在 s******r 的大作中提到】
: update
: keep=id
: as
: drop=a1-a5

l**********s
发帖数: 255
10
Thanks...Just let you know that the results will be different with what I
want.
The following is what I get after running this code.
data two;
input ID a1 a2 a3 a4 a5 abc cnn nb;
datalines;
1 . . . . . 5 6 7
2 . . . . . 7 4 9
3 . 1 1 . . 4 4 4

【在 y****n 的大作中提到】
: data one;
: array aa(5) a1-a5;
: input ID a1 a2 a3 a4 a5 abc cnn nb;
: if sum(of a1-a5)=0 then do;
: do i=1 to 5;
: if aa(i)=0 then aa(i)=.;
: end;
: end;
: drop i;
: datalines;

s******r
发帖数: 1524
11
also the following code could fail if negative number is possible from a1 to 15.
Thanks...Just let you know that the results will be different with what I
want.
The following is what I get after running this code.
data two;
input ID a1 a2 a3 a4 a5 abc cnn nb;
datalines;
1 . . . . . 5 6 7
2 . . . . . 7 4 9
3 . 1 1 . . 4 4 4
1 (共1页)
进入Statistics版参与讨论
相关主题
help! SAS base 70 problem 17/35SAS 问题求助,有包子
SAS里缺失observation补全的问题help for sas program
sas adv 63题 52如何把一个variable中missing 的observation 付上非missing observation 的value
工作中SAS问题 —另一个问题请教!SAS question (紧急求助,在线等)
SAS help needed!包子问,SAS里data long to wide format
新手问个简单的sas问题hi, an interview question
sas里怎么取相邻2个observation的差?请问sas中一个变量的内容被两个左斜杠(/)分成了三部分
一个已经问过的问题(出现新情况),多谢!如何证明数据是伪造的?
相关话题的讨论汇总
话题: a5话题: a1话题: data话题: a2话题: a4