DATA Step, Macro, Functions and more

Index function is not working properly with %let statement

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Index function is not working properly with %let statement

Please considering following two statements. 2nd data step returns correct index function result but 1st one failed. Any sugguestion to make index function work with %let statement? Many thanks.

%let num=%sysfunc(index('/abc/cde/dev/data/ods','/data'));
%put #

data _null_;
num=index('/abc/cde/dev/data/ods','/data');
put num=;
run;

L


Accepted Solutions
Solution
‎08-08-2014 05:43 PM
Super User
Posts: 10,500

Re: Index function is not working properly with %let statement

Try this:

%let num=%index(/abc/cde/dev/data/ods,/data);

%put #

The macro processor generally doesn't use the quotes to deal with strings.

Also there are several MACRO language specific string functions you should use instead of working around the differences when using %sysfunc such as %index, %scan, %substr, %trim and variations such as %Kscan %qkscan,%ksubstr, %ktrim

View solution in original post


All Replies
Solution
‎08-08-2014 05:43 PM
Super User
Posts: 10,500

Re: Index function is not working properly with %let statement

Try this:

%let num=%index(/abc/cde/dev/data/ods,/data);

%put #

The macro processor generally doesn't use the quotes to deal with strings.

Also there are several MACRO language specific string functions you should use instead of working around the differences when using %sysfunc such as %index, %scan, %substr, %trim and variations such as %Kscan %qkscan,%ksubstr, %ktrim

Contributor
Posts: 29

Re: Index function is not working properly with %let statement

Thanks for all your reply. It looks like quotes are not necessary in this case. Both statements work the same below.

%let num=%index(/abc/cde/dev/data/ods,/data);

%put #

%let num=%index(/abc/cde/dev/data/ods,/data);

%put #

Super User
Super User
Posts: 6,500

Re: Index function is not working properly with %let statement

The quotes are considered part of the strings by the macro processor. So there is no match because of the quotes around /data.

See what happens if you try it this way.

%let num=%sysfunc(index(/abc/cde/dev'/data'/ods','/data'));


Contributor
Posts: 29

Re: Index function is not working properly with %let statement

Hi Tom, thanks for your answer. It worked out great.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 424 views
  • 5 likes
  • 3 in conversation