由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - SAS -proc transpose 急问!
相关主题
如何将SAS DATA中的变量名改名(不知道原变量名的前提下)请教用SAS的一个数据处理的问题
SAS problem ask for help!一个sas问题
[合集] 请教:SAS help请问如果用SAS 解决这个问题
one quick question about concatenating data in SAS很挑战的data transformation problem help
sas大牛们这个要怎么实现呀请教:三道SAS BASE题
[SAS] data set options (obs=) in output tablessas 编程 - data manipulation
help for a sas question请教SAS 问题
请教一个SAS问题[SAS]问个简单的data manipulation
相关话题的讨论汇总
话题: type话题: transpose话题: response话题: sas话题: proc
进入Statistics版参与讨论
1 (共1页)
n******9
发帖数: 26
1
原数据如下:
id a b c
1 0 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 0 0 0
。。。
想把以上数据转换成
id type response
1 a 0
1 b 0
1 c 0
1 a 1
1 b 1
1 c 0
1 a 1
1 b 1
1 c 1
2 a 0
2 b 0
2 c 0
2 a 0
2 b 0
2 c 1
。。。
原本以为可以用PROC TRANSPOSE 来做转换,可是总也不能转换成我想要的样子。 肯请
大侠们帮我看看,到底能不能用SAS完成转换。
万分感谢!
A*******s
发帖数: 3942
2
我看了一下by statement的sas help document,原来
The maximum number of observations in any BY group in the input data set is
two;
所以我能想到的变通方法是
data test;
input id a b c;
cards;
1 0 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 0 0 0
;
run;
data test;
set test;
row=_N_;
run;
proc transpose data=test out=out(drop=row rename=(_Name_=type col1=response)
);
by row id;
proc print;
run;
Obs id type response


【在 n******9 的大作中提到】
: 原数据如下:
: id a b c
: 1 0 0 0
: 1 1 1 0
: 1 1 1 1
: 2 0 0 0
: 2 0 0 0
: 。。。
: 想把以上数据转换成
: id type response

f*******e
发帖数: 51
3
不用transpose
data test;
input id a b c;
cards;
1 0 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 0 0 0
;
run;
data test;
set test;
type="a"; response=a; output;
type="b"; response=b; output;
type="c"; response=c; output;
keep id type response;
run;

【在 n******9 的大作中提到】
: 原数据如下:
: id a b c
: 1 0 0 0
: 1 1 1 0
: 1 1 1 1
: 2 0 0 0
: 2 0 0 0
: 。。。
: 想把以上数据转换成
: id type response

d*******o
发帖数: 493
4
data one;
input id @;
do i=1 to 3;
if i=1 then type='a';
if i=2 then type='b';
if i=3 then type='c';
input response @;
drop i;
output;
end;
cards;
1 0 0 0
1 1 1 0
1 1 1 1
2 0 0 0
2 0 0 0
;
run;
n******9
发帖数: 26
5
Thank you so much! Baozi gan xie.
S******y
发帖数: 1123
6
# in case you would like to do it in Python :-)
in_file = 'C:\\to_tranx.txt'
f = open(in_file, 'r')
print 'id','type', 'response'
for line in f:
xid, xa, xb, xc = line.split()
print xid, 'a', xa
print xid, 'b', xb
print xid, 'c', xc
1 (共1页)
进入Statistics版参与讨论
相关主题
[SAS]问个简单的data manipulationsas大牛们这个要怎么实现呀
如何比较两个proc contents的结果?[SAS] data set options (obs=) in output tables
how to trasform data.help for a sas question
如何用SAS Macro来计算这个公式?请教一个SAS问题
如何将SAS DATA中的变量名改名(不知道原变量名的前提下)请教用SAS的一个数据处理的问题
SAS problem ask for help!一个sas问题
[合集] 请教:SAS help请问如果用SAS 解决这个问题
one quick question about concatenating data in SAS很挑战的data transformation problem help
相关话题的讨论汇总
话题: type话题: transpose话题: response话题: sas话题: proc