Help using Base SAS procedures

Dealing with carriage returns in a SAS string

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Dealing with carriage returns in a SAS string

Dear all, would appreciate your help on this.

I have an excel imported data sheet which for the most part looks fine.  Within this imported data I have one character variable which for some cases shows ...  Now if I try and select variables on the basis that this variable contains ... it selects none.  Furthermore when I hover my cursor over the the relevant box on the data screen the pop-up shows a blank line followed by some meaningful text underneath the blank line.  I'm guessing then that the character variable in this case is a carriage return followed by text.  I want to get rid off the CR and just have the text but I can't seem to get compress or trim to do the trick.  Does anyone have any suggestions?  Hope my question is clear enough.

Best wishes,   Chris


Accepted Solutions
Solution
‎08-01-2013 10:36 AM
Occasional Contributor
Posts: 5

Re: Dealing with carriage returns in a SAS string

The syntax for taking out all carriage return ('OD'x) and line feed ('OA'x) characters  is  

comment= Compress(comment,'0D0A'x);

comment= TRANWRD(comment,'0D0A'x,’’);


If you just want to take out the Carriage Return, use this code:  
comment= TRANWRD(comment,'0D'x,'');



Sarath

www.studysas.blogspot.com



View solution in original post


All Replies
Occasional Contributor
Posts: 16

Re: Dealing with carriage returns in a SAS string

I should add that the closest I have got to a solution is

varname = COMPRESS(varname, ' ',"s")

which does indeed get rid of the leading CR, but also unfortunately gets rid of all blanks in the text which is not quite what I want to do.

Solution
‎08-01-2013 10:36 AM
Occasional Contributor
Posts: 5

Re: Dealing with carriage returns in a SAS string

The syntax for taking out all carriage return ('OD'x) and line feed ('OA'x) characters  is  

comment= Compress(comment,'0D0A'x);

comment= TRANWRD(comment,'0D0A'x,’’);


If you just want to take out the Carriage Return, use this code:  
comment= TRANWRD(comment,'0D'x,'');



Sarath

www.studysas.blogspot.com



Occasional Contributor
Posts: 16

Re: Dealing with carriage returns in a SAS string

The compress statement has worked a treat, many thanks Sarath.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 9868 views
  • 1 like
  • 2 in conversation