[code:1e0msw55]data ahuige;
do x1=1 to 4;
do x2=1 to 4;
output;
end;
end;
run;
data ahuige(keep=x:);
set ahuige;
array arr(1:4,1:4)
(
1
2
3
4
[code:1ki9jveb]
data a;
do x1=1 to 4;
do x2=1 to 4;
output;
end;
end;
run;
data b;
set a;
if x1=4 and x2=4 then x12=10;
if x1=3 then x12=x2+5;
if x2=3 then x12=x1+5;
if x1=2 then x12=x2+3;
if x2=2 then x12=x1+3;
if x1=1 then x12=x2;
if x2=1 then x12=x1;
run;
[/code:1ki9jveb]
根据烟酒生的矩阵提示:可以生成任意数列,n=4,5,6,7,8,9。。。。。。。。
[code:1jrjqa9f]
%let n=9;
data a;
do x1=1 to &n;
do x2=1 to &n;
output;
end;
end;
run;
data b;
set a;
tem1=0;
do j=1 to x1;
tem1+(&n-(j-1));
end;
tem1=tem1-&n;
tem2=0;
do j=1 to x2;
tem2+(&n-(j-1));
end;
tem2=tem2-&n;
do i=&n to 1 by -1;
if x1=i then x12=x2+tem1;
if x2=i then x12=x1+tem2;
end;
run;
proc transpose data=b out=c prefix=x2;
by x1;
var x12;
run;
[/code:1jrjqa9f]
ls的做法不错,我也写了一个,不过我的想法是将1至n的数字放入相应的位置中。下面的4可以相应地改为5,6,7,etc。
[code:14r6byxa]data a(keep=i j k);
t=1;
do i=1 to 4; do j=1 to 4;
if j>=i then do k=t;t+1; end; else k=0;
output; end;end;
t=1;
do j=1 to 4; do i=1 to 4;
if i>=j then do k=t; t+1; end;else k=0;
output; end;end;
run;
proc sort data=a;
by i j;
run;
data b(keep=i j q);
set a;
retain q 0;
if i=j then q=k;
else if first.j=1 then q=k;else q+k;
by i j;
if last.j;
run;
proc print; run;
[/code:14r6byxa]