BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Does anyone know of a way of getting SAS to read in files delimited by more than one character? Some files I have to import have over a million records in them, containing customer details entered by call-centre staff over a period of several years. I can't find one single character that will successfully delimit all the records! I figure it will be harder to find a string entered in a record that contains '^$*' than just '^' or '$' or '*'.
I create the files overnight, typically taking the form of:
NAME^AGE^ etc... ('^' being the current delimiter)
Any ideas? I'm using 9.1
5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
You can list multiple delimiters in the DLM= option of the INFILE statement. Delimiters placed next to each other would be treated as one delimiter. Records with only one of the delimiters would be read successfully.

cynthia
[pre]
data readmult;
infile datalines dlm='^$';
input name $ age city $ state $;
return;
datalines;
alan^15$^$Atlanta^GA
bob^$12$^Cary^NC
cathy$14^$Dallas$^$TX
dana^17^Hartford^CT
ed$17$Portland$OR
;
run;

proc print data=readmult;
title 'Use Multiple Delimiters';
run;
[/pre]
LinusH
Tourmaline | Level 20
I don't think this is really what is asked for. I interpret the post as the delimiter always must all of the specified characters in that sequence, just to avoid that some character fields may contain any single of the specified characters.

I don't think that you can do this within the INFILE statement (it would be a great feature though). So I think that you'll have to scan through the whole record searching for the delimiter, maybe using do-loops, FIND function and SUBSTR...

/Linus
Data never sleeps
Peter_C
Rhodochrosite | Level 12
Just about all import routines (may be not oracle, but I'll be happy to be corrected) have a solution to the problem of finding a delimiter character within data values. To protect these (I call delimiters embedded in data) they all support the principle of "Quoting."
The easiest example would be an amount value formatted with the comma. format.
SAS supports the common solution used by (presumeably) all - Quote any value that contains an embedded delimiter.
Ok you may challenge, "what about the quote character turning up in a data value?"
The solution to this seems as standard as the principle of "quoting" - Protect quotes by quoting the string and repeating internal or unbalanced quotes. [pre] Mary said, "let's finish now."[/pre]would be converted to a protected form as [pre] "Mary said, ""let's finish now""."[/pre]
With these methods, text data transfers are achieved in a CSV style that is protected and reliable.
SAS supports this with the DSD option on file statements for creating CSV style, and on the INFILE statement for reading such demimited data.
On no occasion is a more complex delimiter (like a multi-character delimiter word) required.

(just my opinion)

PeterC
deleted_user
Not applicable
I tried the 3rd option as it seemed most like what I was after:
Creating the files with the fields within double quotes (""^""^ etc) worked beautifully - my files imported with no errors or missing values! (1st time in almost a year!)
Thanks to all who replied.
deleted_user
Not applicable
Hi Linus,
yeah we can use DLm option in infile statement and can compress those characters. By the way by using substring function u will just able to extract the portion of that value.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 707 views
  • 0 likes
  • 4 in conversation