DATA Step, Macro, Functions and more

calling INTRR function with a dynamic number of arguments

Reply
Contributor
Posts: 28

calling INTRR function with a dynamic number of arguments

Dear Sir/Madam,

                I want to be able to call the function INTRR with a dynamic number of arguments.

 

My program calls INTRR this way: EIRn = INTRR(1, -Orig_Bal %c(n));

 

My macro c is as follows:

macro c(t);

      %do i = 1 %to term;

            , cf&t(&i)

      %end;

%mend c;

 

This gives me the following errors.

ERROR 71-185: The INTRR function call does not have enough arguments.

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric

       operand is required. The condition was: term

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro C will stop executing.

 

It worked before when my macro c was as follows:

%macro c(t);

      %do i = 1 %to %maxTerm;

            , cf&t(&i)

      %end;

%mend c;

 

But now, every observation has a different Term, and I cannot assign Term to %maxTerm and use it in the same data step.    How can I resolve this error?

 

Thanks,

Warren

Contributor
Posts: 28

Re: calling INTRR function with a dynamic number of arguments

The following answer is from SAS Technical Support.

 

 

Hello Warren,

 

The following is not valid because you cannot place DATA step variables on a %DO loop.  Term is just seen as text. 

 

%do i = 1 %to term;

 

You will need to do this in multiple steps where you create macro variables in the first step to hold each value of term and then use the macro variables in the second step.

 

Thank You,

Russ Tyndall

SAS Technical Support Analyst

SAS Certified Advanced Programmer for SAS 9

Contributor
Posts: 28

Re: calling INTRR function with a dynamic number of arguments

Since my program allows only a maximum of 12 terms, I can simply change my program as follows:

...

%c(n, Term);

...

where the macro c is changed as follows:

 

 

 

%macro c(t, term);

 

select (&term);

 

when (01) EIR&t = INTRR(1,-Orig_Bal,cf&t(1));

when (02) EIR&t = INTRR(1,-Orig_Bal,cf&t(1),cf&t(2));

when (03) EIR&t = INTRR(1,-Orig_Bal,cf&t(1),cf&t(2),cf&t(3));

...

when (12) EIR&t = INTRR(1,-Orig_Bal,cf&t(1),cf&t(2),cf&t(3),cf&t(4),cf&t(5),cf&t(6),

cf&t(7),cf&t(8),cf&t(9),cf&t(10),cf&t(11),cf&t(12));

otherwise put 'ERROR: ' &term=;

end;

 

%mend c;

Ask a Question
Discussion stats
  • 2 replies
  • 209 views
  • 0 likes
  • 1 in conversation