SAS中文论坛

标题: 数据整理求助 [打印本页]

作者: shiyiming    时间: 2007-6-11 18:21
标题: 数据整理求助
我现急需要将数据集aa转换成数据集bb,现在线求助于各位高手,谢谢!
data aa;
input id x1 x2;
cardsl
1 12 13
1 13 15
2 11 12
2 13 14
3 12 11
3 13 11
;run;

data bb;
input id y1 y2 y3 y4;
cards;
1 12 13 13 15
2 11 12 13 14
3 12 11 13 11
;run;

恳请各位高手帮我度过难关,再次谢谢!
作者: shiyiming    时间: 2007-6-12 12:26
标题: Re: 数据整理求助
[code:648a1]
data aa;
input id x1 x2;
cards
;
1 12 13
1 13 15
2 11 12
2 13 14
3 12 11
3 13 11
;
run;

data a1;
  set aa;
  by id;
  if first.id then time =1;
    else time +1;
  run;

data bb (drop = time);
   merge a1(where= (time=1)) a1(where= (time=2) rename =(x1 = x1a  x2 = x2a));
   by ID;
   run;[/code:648a1]
作者: shiyiming    时间: 2007-6-13 01:29
标题: Re: 数据整理求助
非常感谢JOY的无私帮助,可是我的数据集是一个有162万条以上记录的大数据集,同一ID号的数据有1536行,能帮我再想想办法吗?不胜感谢。
作者: shiyiming    时间: 2007-7-11 12:03
标题: Re: 数据整理求助
Joy's solution is the simplest based on the sample data you provided. The solution you wanted are highly dependent on the data sturcture. Base on your descripton, you have 1.62 million rows and 1536 unique ID. Therefore, you have about 1055 observations for each ID. Was your purpose to create a data with
1536 rows and 1055 columns or 2110 columns?

Please give more details before anybody can really help you.
作者: shiyiming    时间: 2007-7-11 20:12
标题: Re: 数据整理求助
hehe, common problem in asking question: when you simplify your question, sometimes it's too simple <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->
作者: shiyiming    时间: 2007-7-12 13:47
标题: Re: 数据整理求助
I am very happy to see you are happy with having stupid structure dataset.

[code:73dbe]data ahuige;
  input id x1 x2;
  cards;
1 12 13
1 13 15
2 11 12
2 13 14
3 12 11
3 13 11
3 56 76
4 2  34
;
run;

proc sort;
  by id;
run;

data final(keep=y1-y3072);
  array y y1-y3072;
  retain y1-y3072 ;
  set ahuige;
  by id;
  n+1;
  y(n*2-1)=x1;
  y(n*2)=x2;
  if last&#46;id then
    do;
    output;
    n=0;
    do i=1 to 3072;
      y(i)=&#46;;
    end;
    end;
run;[/code:73dbe]




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2