What SAS Characters look blank, but are not missing?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

What SAS Characters look blank, but are not missing?

In my dataset, I have a 10-digit phone number field that sometimes has an extra character on the end.  The field appears blank in a proc print, but when I freq the field, it doesn't show as missing

The length of the phone field is 11.  When I put an x at the beginning & end of the field and print it, it looks like:

x0123456789 x

I then made a new variable _11 as substr(phone,11,1) to isolate the missing field.  But when I run a proc freq on _11, it lists 90% of the file as missing and the other 10% with what appears to be a blank (but obviously not missing).

I then made a variable tabFL as substr(phone,11,1) = '09'x, but none of the 10% non-missing blanks were identified.

My question is if there's other SAS Characters that would appear missing, but are not, similar to '09'x?  I also tried the strip function and this apparent missing character was not dropped.

Thanks


Accepted Solutions
Solution
‎04-18-2012 12:50 PM
Super User
Super User
Posts: 7,039

Re: What SAS Characters look blank, but are not missing?

'0D'x is a carriage return. 

There a two main ways I have seen these end up inside your data.

1) Most likely you tried to read a text file created on a Windows machine with SAS on a Unix machine.  The end-of-line on Windows is CR and LF while on Unix it is just LF. So the CR at the end of the line ends up in the data.  You can use INFILE option TERMSTR=CRLF if you know about it in advance.

2) CR inserted into cells in Excel files to break the data into two lines inside the cell.

You can remove them from you variable using the compress, translate or tranwrd function.

For example:

_11 = compress(_11,'0D'x);

View solution in original post


All Replies
Super User
Posts: 5,500

Re: What SAS Characters look blank, but are not missing?

Try converting the "blank" to a hex code:

newvar = put(_11, $hex2.);

Run the PROC FREQ on NEWVAR and you'll see what you're working with.

Occasional Contributor
Posts: 8

Re: What SAS Characters look blank, but are not missing?

Posted in reply to Astounding

They have a value of 0D

Solution
‎04-18-2012 12:50 PM
Super User
Super User
Posts: 7,039

Re: What SAS Characters look blank, but are not missing?

'0D'x is a carriage return. 

There a two main ways I have seen these end up inside your data.

1) Most likely you tried to read a text file created on a Windows machine with SAS on a Unix machine.  The end-of-line on Windows is CR and LF while on Unix it is just LF. So the CR at the end of the line ends up in the data.  You can use INFILE option TERMSTR=CRLF if you know about it in advance.

2) CR inserted into cells in Excel files to break the data into two lines inside the cell.

You can remove them from you variable using the compress, translate or tranwrd function.

For example:

_11 = compress(_11,'0D'x);

Occasional Contributor
Posts: 8

Re: What SAS Characters look blank, but are not missing?

Your scenario 1 is exactly the case.  When I re-ran the infile with the TERMSTR statement you gave the situation resolved itself.

Thanks to both of you for the quick responses!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 713 views
  • 6 likes
  • 3 in conversation