Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage Returns in input field 2

Status
Not open for further replies.

Lmendez

Programmer
Aug 10, 2005
2
US
Does anyone know how to change a carriage return into a blank when reading in an input file that has a long text field that has a carriage return?

I am reading in a dataset that is an extract from Oracle Clinical (SAS View). One of the fields is a memo-type field that allows about 200 characters. I am finding that within this field there is a carriage return, but I need to get rid of it.

I am fairly new to SAS so any suggestions would be wonderful.

Thanks,
Lisa
 
Yep. You need to look up the value for a carriage return. acording to my chart here it is 13 (or 0D). We had a similar issue a while back with NULL characters being returned (value = 0). In that case what I did was
Code:
   if put(trim(user_id),$hex10.) = '00' then user_id = '';
However, it sounds like you have the CR character embeded in amongst actual data in the field. In that case, I reckon this might work
Code:
  new_memo = translate(memo,' ','0D'x);
This should convert a carriage return character into a space (yeah, the syntax for TRANSLATE is a bit funny, you'd think it should be the otherway around). There may also be a Line Feed (LF) character in the field too, as Windows uses a CRLF at the end of a line instead of just a CR. The LF value is 'OA'x, so you may need to do a translate on that too.

TIP - It's generally a good idea to load the amended field into a new field and keep both to start with so that you can examine them, then when you're happy, add a drop option to your Data statement. Earlier versions of SAS have been known to occasionally produce quite odd effects when writing a variable back into itself.
 
Lmendez,
You can also use Chris's method with the COMPRESS() function.
I always thought that SAS uses the return and linefeed chars to end that record, and perhaps that is not the source of your 'null' char. Could there be a non-printable char in your data? I had this very issue with a SAS program that was resaved using msword. There was a non-printable ascii char that existed in that sas program and for two whole days we couldn't understand why the program kept failing. Until we tried (by accident I must add) an older version of that same SAS program. (One saved by a simple text editor.)

Klaz
 
Klaz,

The SAS online documentation says to use compress when the record is of variable length. Can you still use it when the record length is fixed, and the field length is fixed, it's just that the field allows for the carriage returns, tabs, etc.?

You are right, that it may not just be a carriage return. A co-worker mentioned that we also have to deal with tabs, form feeds, and line feeds.

Chris,
Thank you for your tip, it worked. I expanded it to deal with the different non-printable characters that you and Klaz mentioned.

Also, where did you get your chart? I went online and found a couple, but found an ASCII one and a EBCDIC one. What's the difference? I know we need to use the ASCII chart, but was wondering when you would use the EBCDIC one.

Thank you both for your replies. I really appreciate you taking time to help me with my problem.

Lisa
 
Cool, glad to have helped. The chart I have was just one I found somewhere on the net. IT has the character, the decimal value and the hex value. I also recommend a software package called V ( which allows you to view the hex values of your input file which I've found very useful in the past.
Compress is a useful function if you want to strip out specific characters, it can be used on any column and simply removes the specified characters (where translate replaces them with another character. COMPBL() is a variant which removes multiple spaces trimming them down to a single space, you may want to do this after the translate to make sure you don't end up with multiple blanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top