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 - 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: 1532
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: 2445
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: 1532
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: 2445
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: 1532
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 Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm
This topic is locked: you cannot edit posts or make replies. ISREDIT Macro is not returning back t... nico_neoz CLIST & REXX 21 Sat Nov 18, 2017 7:40 pm
No new posts Move from Comp3 variable to Edited Va... Revathy.nair0485 COBOL Programming 7 Fri Nov 03, 2017 3:30 pm
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... nico_neoz COBOL Programming 10 Mon Oct 30, 2017 8:28 am
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am

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