BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasone
Quartz | Level 8

いつも大変お世話になっております。
以下のproc IMLの動きをproc DS2の言葉に書き換えることは可能でしょうか?

data TEST;*テストデータ;
  x=1; y=3; output;
  x=2; y=2; output;
  x=3; y=1; output;
run;

proc iml;
start CrossProd(a, b);
  i231 = {2,3,1};
  i312 = {3,1,2};
  return(a[i231] # b[i312] - a[i312] # b[i231]); 
finish;
  use TEST;*テストデータ;
  read all;
outer = CrossProd(x, y);
  create product var {outer};
  append;
  close product;
quit;

outer=(-4,8,-4)と出力できれば正解なのですが。。
無茶な質問をしてしまって済みません。

1 ACCEPTED SOLUTION

Accepted Solutions
yu_sas
SAS Employee

配列に収めてから計算することは可能かと思います。以下の例では一旦行列に読み込んだ後に配列に戻して計算をしています。

 

proc ds2;
data test2(keep=(outer)) / overwrite=yes;
dcl package matrix m(3,2);
dcl double outer a[3, 2];
vararray double xy[2] x y;

method init();
dcl double i;
 do i=1 to 3;
 set test;
 m.in(xy,i);
 end;
 m.toarray(a);
end;

method run();
dcl double i[3,2] j;
 i:=(2, 3, 3, 1, 1, 2);
 do j=1 to 3;
 outer=a[ i[j,1], 1 ]*a[ i[j,2], 2 ]-a[ i[j,2], 1 ]*a[ i[j,1], 2 ];
 output;
 end;
end;

enddata;
run;
quit;

View solution in original post

2 REPLIES 2
yu_sas
SAS Employee

配列に収めてから計算することは可能かと思います。以下の例では一旦行列に読み込んだ後に配列に戻して計算をしています。

 

proc ds2;
data test2(keep=(outer)) / overwrite=yes;
dcl package matrix m(3,2);
dcl double outer a[3, 2];
vararray double xy[2] x y;

method init();
dcl double i;
 do i=1 to 3;
 set test;
 m.in(xy,i);
 end;
 m.toarray(a);
end;

method run();
dcl double i[3,2] j;
 i:=(2, 3, 3, 1, 1, 2);
 do j=1 to 3;
 outer=a[ i[j,1], 1 ]*a[ i[j,2], 2 ]-a[ i[j,2], 1 ]*a[ i[j,1], 2 ];
 output;
 end;
end;

enddata;
run;
quit;
sasone
Quartz | Level 8

yu_sasさま

 

早速にも有難うございました。
いくつかのデータで試したところ間違いなくIMLの動きになっておりました。
ありがとうございました。

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Discussion stats
  • 2 replies
  • 982 views
  • 1 like
  • 2 in conversation