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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
ballardw
Super User

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

jay_q
Calcite | Level 5

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 #

Tom
Super User Tom
Super User

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'));


jay_q
Calcite | Level 5

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

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
  • 4 replies
  • 1985 views
  • 5 likes
  • 3 in conversation