IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SAS - MACRO index function.


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Tue Sep 06, 2011 9:58 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 06, 2011 11:20 pm
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: 1742
Location: Tirupur, India

PostPosted: Wed Sep 07, 2011 12:03 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts PRINTOUT macro PL/I & Assembler 0
No new posts Cobol file using index COBOL Programming 2
Search our Forums:

Back to Top