Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- how to use %index to get the position of bracket?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2010 12:44 AM

Please see the following code, can anyone tell me why put 0 since &x does contain the brackets?

%let x = a(b);

%put %index(&x, ());

I want to use the code like this in macros, and how to check if a string contains brackets?

%* if brackets contained, then ... ;

%if %index(&x, ()) %then ...

%let x = a(b);

%put %index(&x, ());

I want to use the code like this in macros, and how to check if a string contains brackets?

%* if brackets contained, then ... ;

%if %index(&x, ()) %then ...

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

08-30-2010 02:48 AM

Please read the section on Macro Quoting in and around e.g. http://support.sas.com/onlinedoc/913/getDoc/de/mcrolref.hlp/a001061290.htm

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

08-30-2010 03:00 AM

The index function looks for the second argument exactly not as individual characters. For that you need the INDEXC function. Try:

[pre]%let x = a(b);

%put %sysfunc(indexc(&x,()));

[/pre]

Of course the parentheses are a particularly unfortunate character to have to work with.

[pre]%let x = a(b);

%put %sysfunc(indexc(&x,()));

[/pre]

Of course the parentheses are a particularly unfortunate character to have to work with.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ArtC

08-30-2010 03:55 AM

> The index function looks for the second argument

> exactly not as individual characters. For that you

> need the INDEXC function. Try:

> [pre]%let x = a(b);

> %put %sysfunc(indexc(&x,()));

> [/pre]

> Of course the parentheses are a particularly

> unfortunate character to have to work with.

Oh...yes. %index finds string not characters from given string. I was supposed to know this......a bit dizzy

Thanks a lot.

> exactly not as individual characters. For that you

> need the INDEXC function. Try:

> [pre]%let x = a(b);

> %put %sysfunc(indexc(&x,()));

> [/pre]

> Of course the parentheses are a particularly

> unfortunate character to have to work with.

Oh...yes. %index finds string not characters from given string. I was supposed to know this......a bit dizzy

Thanks a lot.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

12-13-2010 11:42 AM

Try looking for them separately, e.g. find the first one...

12 %let q = %str(%();

13 %put &q;

(

14 %let x = a(b);

15 %put %index(&x, &q);

2

12 %let q = %str(%();

13 %put &q;

(

14 %let x = a(b);

15 %put %index(&x, &q);

2