BookmarkSubscribeRSS Feed
garag
Calcite | Level 5

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

2 REPLIES 2
Peter_C
Rhodochrosite | Level 12

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

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

ballardw
Super User

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.


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 2 replies
  • 925 views
  • 0 likes
  • 3 in conversation