BookmarkSubscribeRSS Feed
RS
Calcite | Level 5 RS
Calcite | Level 5
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
5 REPLIES 5
ArtC
Rhodochrosite | Level 12
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?
art297
Opal | Level 21
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
Peter_C
Rhodochrosite | Level 12
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
RS
Calcite | Level 5 RS
Calcite | Level 5
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
Patrick
Opal | Level 21
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1467 views
  • 0 likes
  • 5 in conversation