DATA Step, Macro, Functions and more

Reading text files with carriage returns

Reply
New Contributor RS
New Contributor
Posts: 3

Reading text files with carriage returns

Hi,

I have a text file where the total record length may come to 1500 in a row. In many fields carraige returns and line feeders are present and moreover the fields are embedded by double quotes and separated by commas. I have converted this text file from Microsoft access where I have lot of missing values. How can I create a sas dataset without data mismatch and without errors using this text file. Your reply is deeply appreciated.

Thanks.
RS
Valued Guide
Posts: 634

Re: Reading text files with carriage returns

We are going to need a bit more info.

How are you converting from MS/Access to SAS - DATA step or PROC IMPORT? What conversion engines do you have available? You mention a text file; is it being created by MS/Access, and do you have access to its generation process? Are you running SAS9.2? Can we assume that the OS is windows?
PROC Star
Posts: 7,471

Re: Reading text files with carriage returns

Since no one has responded, I'm not alone in thinking that you didn't provide enough information.

Does the file's first record indicate the fields that are represented in the data?

Is the only problem being that one actual record may be represented over multiple records?

Are all fields either separated by commas or at least the last field on a particular line?

Art
Valued Guide
Posts: 2,177

Re: Reading text files with carriage returns

RS
If you have SAS9.2, then use the TERMSTR= option of the INFILE statement.
With that option set to CRLF the single embedded LF will not cause the infile buffer parsing any trouble (as happened before SAS9.2)

good luck
peterC
New Contributor RS
New Contributor
Posts: 3

Re: Reading text files with carriage returns

Hi Friends,

Thanks for sending your suggestions. And sorry that I haven't responded immediately. The OS is windows and SAS version is 9.2. The Carriage Returns (CR) and Line Feeders (LF) are not present in first row and the fields are separated by commas and the values are given in double codes. The CR and LF are present in source file, i.e. access file and I have created a text file from here.
I have used PROC import using DBMS=accesscs option and now I can able to create SAS datasets but however these CR and LF need to be removed in SAS datasets.

Thanks a lot.

-RS
Respected Advisor
Posts: 4,173

Re: Reading text files with carriage returns

Hi

compress() with modifier for control characters should do the job, ie:

data want;
set have;
array charvars {*} _character_;
do i=1 to dim(charvars);
charvars{i}=compress(charvars{i},,'c');
end;
run;

HTH
Patrick
Ask a Question
Discussion stats
  • 5 replies
  • 319 views
  • 0 likes
  • 5 in conversation