楼主: sunset1986
1327 7

请教一个多条数据和并成一条的问题,十分感谢大家 [推广有奖]

  • 4关注
  • 23粉丝

已卖:100份资源

院士

16%

还不是VIP/贵宾

-

威望
1
论坛币
1505 个
通用积分
0.1258
学术水平
42 点
热心指数
49 点
信用等级
23 点
经验
31956 点
帖子
2535
精华
0
在线时间
715 小时
注册时间
2012-2-6
最后登录
2014-5-26

楼主
sunset1986 发表于 2012-9-27 17:30:35 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Id

a

b

c

d

e

f

1

1

1

36

37

84

89

1

0

0

62

22

55

19

1

1

0

13

75

74

83

2

1

0

33

76

48

43

2

1

0

29

71

73

22

3

1

1

25

33

100

22

3

0

1

77

92

16

68

4

0

1

20

61

14

20

5

0

0

5

14

70

92

5

1

1

85

21

50

51

6

1

1

75

100

56

28

6

0

0

68

94

56

28


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ABCD ABC CDE def 希望

An honest tale speeds best being plainly told.
Cheers!

沙发
sunset1986 发表于 2012-9-27 17:32:01
数据如上,希望得到的结果是:同样的Id,把多条数据和并成一条,也就是说,呈现下面这种形式 (或者更好的形式):

Id a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 a3 b3 c3 d3 e3 f3
1 1 0 56 85 18 35 0 1 81 44 34 57 1 1 32 13 6 11
2 1 0 60 71 86 48 1 1 67 75 65 83      
3 1 0 34 17 94 24 0 1 59 35 97 39      
4 0 1 49 9 7 69            
5 0 1 23 67 63 21 1 1 37 79 96 60      
6 1 1 12 6 66 32 0 0 81 97 83 18            

万分感激
An honest tale speeds best being plainly told.
Cheers!

藤椅
pobel 在职认证  发表于 2012-9-27 19:11:45
data test;
  input Id $        a         b        c        d        e        f;
  cards;
1        1        1        36        37        84        89
1        0        0        62        22        55        19
1        1        0        13        75        74        83
2        1        0        33        76        48        43
2        1        0        29        71        73        22
3        1        1        25        33        100        22
3        0        1        77        92        16        68
4        0        1        20        61        14        20
5        0        0        5        14        70        92
5        1        1        85        21        50        51
6        1        1        75        100        56        28
6        0        0        68        94        56        28
;

data test;
    set test;
        by id;
        if first.id then n=1;
        else n+1;
run;

proc transpose data=test out=test1;
   by id n;
   var a b c d e f;
run;

data test2;
    set test1;
        _name_=cats(_name_,n);
run;

proc transpose data=test2 out=test3;
   by id;
   var col1;
   id _name_;
run;
和谐拯救危机

板凳
sunset1986 发表于 2012-9-28 09:12:36
pobel 发表于 2012-9-27 19:11
data test;
  input Id $        a         b        c        d        e        f;
  cards;
十分感谢!
An honest tale speeds best being plainly told.
Cheers!

报纸
jingju11 发表于 2012-9-28 09:53:12
  1. data have;
  2. drop i x  a b c d e f;
  3. set had; by id notsorted;
  4. array tt[3,6] a1 b1 c1 d1 e1 f1
  5.               a2 b2 c2 d2 e2 f2
  6.               a3 b3 c3 d3 e3 f3
  7.               (18*.);
  8. arry vv[6] a b c d e f;
  9. x ++1;
  10. do i =1 to 6;
  11.   tt[x,i] =vv[i];
  12. end;
  13. if last.id then do;
  14.   output;
  15.   x =0; call missing(of tt[*]);
  16. end;
  17. run;
复制代码
Hopefully it works. if it does, i will put it to my blog tomorrow. jingju

地板
sunset1986 发表于 2012-9-28 10:27:45
jingju11 发表于 2012-9-28 09:53
Hopefully it works. if it does, i will put it to my blog tomorrow. jingju
Thanks a lot.
one quick question, in your code, do you suppose that the 'had' dataset you set is the orignal dataset which is expected to be transposed?
An honest tale speeds best being plainly told.
Cheers!

7
jingju11 发表于 2012-9-28 10:34:59
had is your original data set--with grouped id. what i am doing is to find the alternative to transpose jingu

8
sunset1986 发表于 2012-9-28 12:13:29
jingju11 发表于 2012-9-28 10:34
had is your original data set--with grouped id. what i am doing is to find the alternative to transp ...
Sure, it does work. The result exactly matches with my expectation. Appreciate.
One question: what's the function of x++1. In other words, how does it work among array statement.
One concern: In advance of executing the code, I need to check the number of records of each ID to find the max. After that, I can set the dimension of the array tt.

All in all, sincerely grateful for your help.
An honest tale speeds best being plainly told.
Cheers!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 12:29