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

Hello,

I'm new to PROC FCMP and am trying to get it to do some matrix multiplication as a subroutine.

As an example I have two matrices:

Z:

LOBSIMZ
A1-0.326592916
B11.542436865

CORR:

AB
10.5
0.51

This is as far as I've gotten:

DATA Z;

   INPUT LOB $ SIM Z;

   DATALINES;

A 1 -0.326592916

B 1 1.542436865;

RUN;

DATA CORR;

   INPUT A B;

   DATALINES;

1 0.5

0.5 1;

RUN;

PROC FCMP OUTLIB=WORK.FUNCS.MATRIX;

  SUBROUTINE MMULT(SIM);

  ARRAY Y[2]; OUTARGS Y;

  ARRAY CORR[2,2] / NOSYMBOLS;

  ARRAY Z[2] / NOSYMBOLS;

  RC = READ_ARRAY('CORR', CORR);

  RC = READ_ARRAY('Z', Z, 'Z');

  CALL MULT(Z, CORR, Y);

  RC = WRITE_ARRAY('Z', Y, 'Y');

  ENDSUB;

QUIT;

OPTIONS CMPLIB=WORK.FUNCS;

DATA TEST;

  SET Z;

  DO SIM=1 TO 1;

  CALL MMULT(SIM);

  END;

RUN;

...and I'm still getting these errors:

ERROR: Argument 3 to subroutine MULT must be a matrix at line 0 column 13.

ERROR: Error reported in function 'MULT' in statement number 5 at line 10 column 4.

Any help would be greatly appreciated!

Thanks

Emre

1 ACCEPTED SOLUTION

Accepted Solutions
feyzi
Calcite | Level 5

This works:

PROC FCMP OUTLIB=WORK.FUNCS.MATRIX;

  SUBROUTINE MMULT(SIM);

  ARRAY Y[2]; OUTARGS Y;

  ARRAY CORR[2,2] / NOSYMBOLS;

  ARRAY Z[2] / NOSYMBOLS;

  RC1 = READ_ARRAY('CORR_COP', CORR);

  RC2 = READ_ARRAY('Z', Z, 'Z');

  CALL MULT(Z, CORR, Y);

  RC3 = WRITE_ARRAY('Y', Y, 'Y');

  PUT Z=;

  PUT CORR=;

  PUT Y=;

  ENDSUB;

QUIT;

OPTIONS CMPLIB=WORK.FUNCS;

DATA TEST;

  SET Z;

  DO SIM=1 TO 1;

  CALL MMULT(SIM);

  OUTPUT;

  END;

RUN;

View solution in original post

1 REPLY 1
feyzi
Calcite | Level 5

This works:

PROC FCMP OUTLIB=WORK.FUNCS.MATRIX;

  SUBROUTINE MMULT(SIM);

  ARRAY Y[2]; OUTARGS Y;

  ARRAY CORR[2,2] / NOSYMBOLS;

  ARRAY Z[2] / NOSYMBOLS;

  RC1 = READ_ARRAY('CORR_COP', CORR);

  RC2 = READ_ARRAY('Z', Z, 'Z');

  CALL MULT(Z, CORR, Y);

  RC3 = WRITE_ARRAY('Y', Y, 'Y');

  PUT Z=;

  PUT CORR=;

  PUT Y=;

  ENDSUB;

QUIT;

OPTIONS CMPLIB=WORK.FUNCS;

DATA TEST;

  SET Z;

  DO SIM=1 TO 1;

  CALL MMULT(SIM);

  OUTPUT;

  END;

RUN;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1154 views
  • 0 likes
  • 1 in conversation