Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
SAS - MACRO index function.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1521
Location: Chennai

PostPosted: Tue Sep 06, 2011 9:58 pm    Post subject: SAS - MACRO index function.
Reply with quote

Hi,

There is a SAS macro variable text1 with the value,
this is a text with ' , ) , % and )

I am trying to find the position of the first occurernce of ) on the SAS macro variable using index function.

Tried the below code, but unable to make the %index or %qindex to work,
could you please let me know how to correct the statements.
CODE:
Code:
option symbolgen mprint;                               
%let text1 = this is a text with %str(%') , ) , % and );
%put &text1;                                           
%let text2 = %qindex("%str(&text1)","%str(%))");       
%put &text2;                                           


LOG:
Code:
1    option symbolgen mprint;                                               
2    %let text1 = this is a text with %str(%') , ) , % and );               
3    %put &text1;                                                           
SYMBOLGEN:  Macro variable TEXT1 resolves to this is a text with ' , ) , % 
            and )                                                           
SYMBOLGEN:  Some characters in the above value which were subject to macro 
            quoting have been unquoted for printing.                       
this is a text with ' , ) , % and )                                         
4    %let text2 = %qindex("%str(&text1)","%str(%))");                       
WARNING: Apparent invocation of macro QINDEX not resolved.                 
SYMBOLGEN:  Macro variable TEXT1 resolves to this is a text with ' , ) , % 
            and )                                                           
SYMBOLGEN:  Some characters in the above value which were subject to macro 
            quoting have been unquoted for printing.                       
5    %put &text2;                                                           
SYMBOLGEN:  Macro variable TEXT2 resolves to %qindex("this is a text with '
            , ) , % and )",")")                                             
SYMBOLGEN:  Some characters in the above value which were subject to macro 
            quoting have been unquoted for printing.                       
WARNING: Apparent invocation of macro QINDEX not resolved.                 
%qindex("this is a text with ' , ) , % and )",")")                         


Thanks for viewing.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Tue Sep 06, 2011 11:20 pm    Post subject:
Reply with quote

What is %QINDEX -- it is not listed as a SAS macro function in anything I can find?

This worked for me:
Code:
%LET TEXT1 = THIS IS A TEXT WITH %STR(%') , ) , % AND );
%PUT &TEXT1;
%LET TEXT3 = %STR(%)) ;
%PUT &TEXT3;
%LET TEXT2 = %INDEX(%UNQUOTE("%NRSTR(%BQUOTE(&TEXT1))"),&TEXT3);
%PUT &TEXT2;
Note the %INDEX function does NOT have quotes around the second parameter. The result returned for TEXT2 is 26 -- which is the first position of the parenthesis, counting the space after the equal sign of the %LET TEXT1= statement, and resolving the %STR function.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1521
Location: Chennai

PostPosted: Wed Sep 07, 2011 12:03 am    Post subject:
Reply with quote

Hello Robert,
Thanks for your thoughts.
Quote:
What is %QINDEX -- it is not listed as a SAS macro function in anything I can find?

It was my error. Functions like SUBSTR,SCAN,UPCASE have QSUBSTR,QSCAN,QUPCASE pair so I used QINDEX without looking it up.
Realised now that Q prefix is only for functions which return a character.

This also worked now,
Code:
option symbolgen mprint;                                 
%let text1 = this is a text with %str(%') , ) , % and );
%put &text1;                                             
%let text2 = %index("%str(&text1)",%STR(%)));           
%put &text2;                                             


Thanks again.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts exec macro in the end of edit anatol CLIST & REXX 0 Fri Sep 22, 2017 5:10 am
No new posts How to Run Rexx Macro? Kalaivignesh CLIST & REXX 5 Fri Sep 01, 2017 9:08 pm
No new posts Confusion b/w index and subscript Deepak kumar25 Mainframe Interview Questions 7 Thu Aug 31, 2017 6:50 am
No new posts ISREDIT MACRO NOT WORKING! :cry: kirank889 TSO/ISPF 3 Thu Aug 03, 2017 5:46 pm
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us