LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 25 Sep 2003 14:42:24 -0700
Reply-To:   "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Subject:   Re: SAS and line breaks
Comments:   To: Francis Harvey <HARVEYF1@WESTAT.COM>
Content-Type:   text/plain

From the v9 documentation:

-------------------------------------------------------------

Altering the Record Format

Using the RECFM= option in the FILENAME, FILE, %INCLUDE, and INFILE statements enables you to specify the record format of your external files. The following example shows you how to use this option.

Usually, SAS reads a line of data until a carriage return and line feed combination ('0D0A'x) are encountered or until just a line feed ('0A'x) is encountered. However, sometimes data do not contain these carriage control characters but do have fixed-length records. In this case, you can specify RECFM=F to read your data.

To read such a file, you need to use the LRECL= option to specify the record length and the RECFM= option to tell SAS that the records have fixed-length record format. Here are the required statements:

data test; infile "test.dat" lrecl=60 recfm=f; input x y z; run;

In this example, SAS expects fixed-length records that are 60 bytes long, and it reads in the three numeric variables X, Y, and Z.

You can also specify RECFM=F when your data do contain carriage returns and line feeds, but you want to read these values as part of your data instead of treating them as carriage control characters. When you specify RECFM=F, SAS ignores any carriage controls and line feeds and simply reads the record length you specify.

------------------------------------------------------------

I'd suggest reading through the data with recfm=f, and replacing any occurrence of CR with the CR-LF or just LF.

I know in Unix there's a DOS2Unix utility or something like that. I'd bet there's similar MAC to PC utilities.

Paul Choate DDS Data Extraction (916) 654-2160

-----Original Message----- From: Francis Harvey [mailto:HARVEYF1@WESTAT.COM] Sent: Thursday, September 25, 2003 1:36 PM To: SAS-L@LISTSERV.UGA.EDU Subject: SAS and line breaks

Greetings,

I recently had an interesting file put before a program I wrote for automatic processing that left me wondering what the best approach to handling it is. This document was apparently written on a MAC as it has lines that are broken only by carriage returns (CR) and then reformatted on a PC with normal line breaks of carriage returns (CR) followed by a line feed (LF).

When reading this file using SAS on a PC (which is where the processing program runs), I initially PAD the source file to 100 characters (no line can be longer than that) and then load the data. However, I am finding that SAS is not treating the CR without an LF as a line break. My first inclination is to force the user to clean the file to remove the problem before using my program, but I may be overreacting. Another interesting point is that our Linux server may become more widely used in the future or we may obtain UNIX generated documents to reprocess which could cause there to be lines with an LF without a matching CR.

So, would you force SAS to deal directly with such files, and if so, how would you alter the data step to get them to process properly? I am just going to assume that I will never see a file that has been processed on both a MAC and a UNIX box as that would just seem to be something I would have to talk to the individual about.

Francis R. Harvey III WB 303, x3952 harveyf1@westat.com

VB programmers know the wisdom of Nothing


Back to: Top of message | Previous page | Main SAS-L page