SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Satish_Parida
Lapis Lazuli | Level 10

Hi Experts,

 

I am trying to substitute line feed to my character variable, in place of a pattern. I have used following attempts.

 

  1. translate(TRIM(Itemdata_Value),'0a'x,'XXXXXXXXX');
    1. Issue: It is creating both line feed and carriage return for some reason. i.e 2 line breaks, where I want one.
  2. prxchange("s/XXXXXXXXX/\n/", -1, Itemdata_Value);
    1. It simply replaced XXXXXXXX with text /n, not new line

Please help. 

Ref:

https://communities.sas.com/t5/SAS-Procedures/SAS-new-line-symbol-character-code/td-p/27843

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Translate replaces characters from the list with equivalent characters from the replace list, not the whole word.  Tranwrd is the tool for replacing a whole text string with something else.  Per the manual:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215153.htm

 

The prx is simply replacing the text string with the text string /n as you say, and that is correct.  The /n means newline in some file formats,much like ^{newline} can be used in rtf code.  Therefore the code is working, but your output renderer (rtf, pdf etc.) is either not setup to use the /n syntax, or its not valid for that renderer.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use:

itemdata_value=tranwrd(itemdata_value,"XXXXXXXX",'0a'x);
Satish_Parida
Lapis Lazuli | Level 10
This worked,Thank you, but it is very strange the translate did not work and /n character did not resolve to new line.
If any one can clarify in this thread, then it may help someone in future.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Translate replaces characters from the list with equivalent characters from the replace list, not the whole word.  Tranwrd is the tool for replacing a whole text string with something else.  Per the manual:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215153.htm

 

The prx is simply replacing the text string with the text string /n as you say, and that is correct.  The /n means newline in some file formats,much like ^{newline} can be used in rtf code.  Therefore the code is working, but your output renderer (rtf, pdf etc.) is either not setup to use the /n syntax, or its not valid for that renderer.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3347 views
  • 4 likes
  • 2 in conversation