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

SAS - String replace in macro variable.


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: Wed Aug 24, 2011 12:37 pm
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: 2481
Location: Netherlands, Amstelveen

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

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: 1742
Location: Tirupur, India

PostPosted: Wed Aug 24, 2011 2:01 pm
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: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Aug 24, 2011 2:08 pm
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: 1742
Location: Tirupur, India

PostPosted: Wed Aug 24, 2011 2:21 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top