How to remove a line feed from a field ?

Remove CRLF Issue from SAS data

Sometimes in our SAS data, we encounter a problem of CRLF ( Carriage Return - Line Feed) in a variable. What's that ???

Have you ever seen a old type of type writer, In that during typing, once one line gets full, we need to return the print carriage to old position and give a line feed to start typing in the next line. We do the same in modern computers, pressing "Enter" key while typing.

It is Okay to have CRLF in existence, but not in our data. While we export such data having CRLF within a field, it creates big havoc ?Let's explore it in detail and also check the remedy in SAS ...

Let us first create a problem ... see how to identify it and then how to solve it.

Create Problematic dataset:

Data problem;
infile datalines dsd;
input part_1 $  part_2 $   part_3    ;
Customer_ID  = catx('0A'x, part_1, part_2, part_3 );

SAS uses '0A'x denotation for CRLF, so in the above code, we are concatenating the three strings with this in between.

We actually don't create such issues ourselves (here we are doing for demonstration purpose only), often such issues come, whenever there is a migration of data across Windows and Unix operating systems (either way).

Detect the Issue in Data :

Try exporting the above data :

Proc export data = problem
outfile = "Location\check.csv" replace;

** please give location of some folder in your PC in place of location.

You will see the data would like :

Got the Problem .... Imagine, how detrimental such issue can be for a large dataset.

So how to check such issue without exporting.

Well, this '0A'X is visible to us once, we convert the data into its hexadecimal form.

Data problem;
set  problem;
new = put(Customer_ID,hex.);

Solve the problem :

Very simple, just compress it ...

Data problem;
set  problem;
customer_id = compress(Customer_ID,'0A'x);

Now try exporting it ... everything would be fine now .

Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.