Created
March 21, 2015 06:10
-
-
Save Prunus1350/fd015501fb1e80c51b24 to your computer and use it in GitHub Desktop.
DS2 Languageで逆行列
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro inv_matrix(in1=, out1=); | |
%local i; | |
proc contents data = &in1. out = __m1(keep=name varnum nobs) noprint; | |
run; | |
* 変数名・行数・列数をマクロ変数に格納 ; | |
data _null_; | |
set __m1 end = eof; | |
call symputx("x1_" || compress(put(_n_, best.)), name); | |
if eof then do; | |
call symputx("r1", nobs); | |
call symputx("c1", varnum); | |
end; | |
run; | |
* 変数名を変換 ; | |
data _m1; | |
set &in1.; | |
rename %do i = 1 %to &c1.; | |
&&x1_&i.. = x1_&i. | |
%end; | |
; | |
run; | |
* 逆行列を計算 ; | |
proc ds2; | |
data &out1. / overwrite = yes; | |
drop i x:; | |
declare double i; | |
vararray double x1_[&c1.]; | |
vararray double z[&c1.]; | |
declare package matrix m1 m2; | |
method init(); | |
m1 = _new_ [this] matrix(&r1., &c1.); | |
do i = 1 to &r1.; | |
set _m1; | |
m1.in(x1_, i); | |
end; | |
end; | |
method term(); | |
m2 = m1.inverse(); | |
do i = 1 to &r1.; | |
m2.out(z, i); | |
output; | |
end; | |
end; | |
enddata; | |
run; | |
quit; | |
%mend inv_matrix; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment