Skip to content

Instantly share code, notes, and snippets.

@Prunus1350
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prunus1350/a118c7e1788b131f7ddd to your computer and use it in GitHub Desktop.
Save Prunus1350/a118c7e1788b131f7ddd to your computer and use it in GitHub Desktop.
DS2 Languageで行列の積
%macro mult_matrix(in1=, in2=, out1=);
%local i j;
%do i = 1 %to 2;
proc contents data = &&in&i.. out = __m&i.(keep=name varnum nobs) noprint;
run;
* 変数名・行数・列数をマクロ変数に格納 ;
data _null_;
set __m&i. end = eof;
call symputx("x&i._" || compress(put(_n_, best.)), name);
if eof then do;
call symputx("r&i.", nobs);
call symputx("c&i.", varnum);
end;
run;
* 変数名を変換 ;
data _m&i.;
set &&in&i..;
rename %do j = 1 %to &&c&i..;
&&x&i._&j.. = x&i._&j.
%end;
;
run;
%end;
* 行列の積を計算 ;
proc ds2;
data &out1. / overwrite = yes;
drop i x:;
declare double i;
vararray double x1_[&c1.];
vararray double x2_[&c2.];
vararray double z[&c2.];
declare package matrix m1 m2 m3;
method init();
m1 = _new_ [this] matrix(&r1., &c1.);
m2 = _new_ [this] matrix(&r2., &c2.);
do i = 1 to &r1.;
set _m1;
m1.in(x1_, i);
end;
do i = 1 to &r2.;
set _m2;
m2.in(x2_, i);
end;
end;
method term();
m3 = m1.mult(m2);
do i = 1 to &r1.;
m3.out(z, i);
output;
end;
end;
enddata;
run;
quit;
%mend mult_matrix;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment