Can anybody help with an alternative dynamic code that can work with upto 12*12 matrix for the below code without using Proc IML:-
data abc;
input a b;
cards;
1 1
2 2
;
run;
proc iml;
use abc;
read all into A1;
B1=A1**12;
create def from B1;
append from B1;
close def;
print A1;
print B1;
quit;
Hello @Venky3110,
I think you can build something around the CALL POWER routine of PROC FCMP.
Here's a quick example:
proc fcmp outlib=work.funcs.test;
subroutine matpow(inds $, outds $, e);
array A1[12,12] / nosymbols;
array B1[12,12] / nosymbols;
rc=read_array(inds, A1);
call dynamic_array(B1,dim1(A1),dim2(A1));
call power(A1, e, B1);
rc=write_array(outds,B1);
endsub;
run;
options cmplib=work.funcs;
data have;
input a b;
cards;
1 2
3 4
;
data _null_;
call matpow('have','want',12);
run;
proc print data=want noobs;
run;
Result:
B11 B12 138067399 201223170 301834755 439902154
You could use a DATA step with an array
data want;
set abc;
array x _numeric_;
do i=1 to dim(x);
x(i)=x(i)**12;
end;
drop i;
run;
@PaigeMiller Thanks for response.But the output is not matching with my requirement
@Venky3110 wrote:
@PaigeMiller Thanks for response.But the output is not matching with my requirement
Sorry, disregard my answer above. I forgot that IML ** is different than data step **.
Hello @Venky3110,
I think you can build something around the CALL POWER routine of PROC FCMP.
Here's a quick example:
proc fcmp outlib=work.funcs.test;
subroutine matpow(inds $, outds $, e);
array A1[12,12] / nosymbols;
array B1[12,12] / nosymbols;
rc=read_array(inds, A1);
call dynamic_array(B1,dim1(A1),dim2(A1));
call power(A1, e, B1);
rc=write_array(outds,B1);
endsub;
run;
options cmplib=work.funcs;
data have;
input a b;
cards;
1 2
3 4
;
data _null_;
call matpow('have','want',12);
run;
proc print data=want noobs;
run;
Result:
B11 B12 138067399 201223170 301834755 439902154
@FreelanceReinh Thanks for the code. It is working fine. The output is perfect.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.