问题1:想把data a 改成单行 i.e.:
data b;
m_id x1 y1 x2 y2 x3 y3;
a1 1 12 15 20 22 28
问题2:如果data a 有上百行数据,又该如何?
data a;
input m_id $ x y;
cards;
a1 1 12
a1 15 20
a1 22 28
a1 30 36
. . .
;
run;
thx!!!作者: shiyiming 时间: 2013-5-2 11:08 标题: Re: 如何把多行变量值改写成一行? 参考http://saslist.net/archives/255。里面详细讲述关于转置的方法与代码。作者: shiyiming 时间: 2013-5-2 23:21 标题: Re: 如何把多行变量值改写成一行? it is different from the 转置的方法与代码 in this website, actually my case is a little more complicated. anyway, any comments/suggestion is welcome,.
thanks again.作者: shiyiming 时间: 2013-5-3 13:08 标题: Re: 如何把多行变量值改写成一行? 用Merge作者: shiyiming 时间: 2013-5-10 00:08 标题: Re: 如何把多行变量值改写成一行? using data-step can refer the following code. Jingju
[code:cfkjdgrz]proc sql noprint;
select max(c) into :maxn from (select count(*) as c from sashelp.class(keep =age) group by age) ;
data have;
set sashelp.class; by age notsorted;
array t[&maxn, 2] %makevars(%eval(2*&maxn)*.);
n ++1;
t[n, 1] =height; t[n, 2] =weight;
if last.age then do;
output; call missing(of t[*] n);
end;
keep age %makevars;
run;[/code:cfkjdgrz]作者: shiyiming 时间: 2013-6-27 20:42 标题: Re: 如何把多行变量值改写成一行? [code:21dz4emw]proc transpose data=a(drop=y) out=b1 prefix=x;
var x ;
by m_id;
run;
proc transpose data=a(drop=x) out=b2 prefix=y;
var y ;
by m_id;
run;
data b;
merge b1 b2;
by m_id;
drop _name_;
run;[/code:21dz4emw]