Friday, August 10, 2012

To remove Carriage Return and/or Linefeed characters

Couple days ago, one of my programs, which used to compare two sets of SAS datasets, gave me warnings with discrepancies found. I checked the data manually, and figured out that the issues were because of one set of SAS datasets containing CR/LF characters.

I did use function STRIP to remove extra blank chars. I thought that SAS functions, like STRIP, TRIM, CATS, etc., could remove blank characters, like space or CR/LF. Actually, they are not.

Since CR is '0D'x, and LF is '0A'x, there are at least two functions that will do the job.
1) compress(source_text, '0D0A'x);
2) prxchange('s/(\n|\r)//', -1, source_text);

3 comments:

  1. I cannot thank you enough for this!! I was pulling my hair out when I finally figured out there were carriage returns in my character variable. This got rid of them and returned my data to it's more manageable state!
    Thanks!

    ReplyDelete
  2. Thanks mate, You are the man...

    ReplyDelete
  3. You are my lifesaver. Thank you so much!

    ReplyDelete