Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SAS - String replace in macro variable.

 
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: 1504
Location: Chennai

PostPosted: Wed Aug 24, 2011 12:37 pm    Post subject: SAS - String replace in macro variable.
Reply with quote

Hello,
We have a macro input variable like,
Code:
%LET INPUT_TEXT = S O  M E TEXT;


All the spaces in the macro variable "INPUT_TEXT" needs to be converted into "<SP>"
For above input the output required would be,
Code:
S<SP>O<SP><SP>M<SP>E<SP>TEXT

Could you please let me know how to do this,
I tried the below code, but it does not work :S
Code:

OPTIONS SYMBOLGEN MPRINT;                                       
%LET INPUT_TEXT = S O  M E TEXT;                                 
%MACRO REPLACE;                                                 
  %LET OUTPUT_TEXT = %SYSFUNC(TRANWRD("&INPUT_TEXT","<SP>"," "));
  %PUT &OUTPUT_TEXT;                                             
%MEND;                                                           
%REPLACE;                                                       


Log:
Code:
SYMBOLGEN:  Macro variable INPUT_TEXT resolves to S O  M E TEXT     
SYMBOLGEN:  Macro variable OUTPUT_TEXT resolves to "S O  M E TEXT" 
"S O  M E TEXT"                                                     

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

PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2435
Location: Netherlands, Amstelveen

PostPosted: Wed Aug 24, 2011 1:41 pm    Post subject:
Reply with quote

http://www.sascommunity.org/wiki/SAS/Macro_String_Replace_Function

The string to be changed is passed to the macro in previous link.
I guess it has to do with local/global variable scope.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1504
Location: Chennai

PostPosted: Wed Aug 24, 2011 2:01 pm    Post subject:
Reply with quote

Hello Peter,
Thanks for the link with the program.

Let me test it.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2435
Location: Netherlands, Amstelveen

PostPosted: Wed Aug 24, 2011 2:08 pm    Post subject:
Reply with quote

TRANWRD(source,target,replacement)

I think you swapped target and replacement.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1504
Location: Chennai

PostPosted: Wed Aug 24, 2011 2:21 pm    Post subject:
Reply with quote

The solution on the link worked well and solved the issue.

Today I learnt that TRANWRD and TRANSLATE have different order of target and replacement. Eventhough they do almost similar task.

TRANWRD(source,target string,replacement string)
TRANSLATE(source,replacement,target)

Thanks & Regards,
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 Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us