BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Venky3110
Fluorite | Level 6

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;

 

 

 

Venky3110_0-1692704375487.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller
Venky3110
Fluorite | Level 6
The output is not matching
Venky3110
Fluorite | Level 6

@PaigeMiller Thanks for response.But the output is not matching with my requirement

 

PaigeMiller
Diamond | Level 26

@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 **.

--
Paige Miller
Venky3110
Fluorite | Level 6
No Problems.Thanks for Trying.
FreelanceReinh
Jade | Level 19

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

 

Venky3110
Fluorite | Level 6

@FreelanceReinh Thanks for the code. It is working fine. The output is perfect.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1124 views
  • 2 likes
  • 3 in conversation