DATA Step, Macro, Functions and more

Index function strange behaviour

Reply
Contributor
Posts: 58

Index function strange behaviour

Hi,

running the following code:

%macro boh;

data _null_;
    a="aaaaBIANNUAL";
    b="BIANNUAL";
    q=index(a,b);
    w=index(a,trim(b));
    put q= w=;
run;

%put %index("aaaaBIANNUAL", %trim("BIANNUAL")) ;

%mend;
%boh;

I get this result:

q=5 w=5

0

it semmes that the function index work in two different way if used in a data step or in a macro (in the datastep in a correct wat, in the macro does not work)

Does someone know the reason?

Many thanks.

Bye

Antonio

Valued Guide
Posts: 2,177

Re: Index function strange behaviour

take the quotes out of the %put statement and try again.

Message was edited by: Peter Crawford  Should clarify the statement to change

Super User
Posts: 11,343

Re: Index function strange behaviour

Macro functions generally are text manipulators and do NOT require the quotes to distinguish between variable names and string literals as in a datastep. If you put a quote in any of the argument strings it is treated as being a part of the string. So "BIANNUAL" is not part of aaaaBIANNUAL in any way.


Ask a Question
Discussion stats
  • 2 replies
  • 222 views
  • 0 likes
  • 3 in conversation