BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
procsql
Fluorite | Level 6

Hi wonderful SAS community!

 

I am trying to create a data step view for a large text file. The text file has the following delimiter    "|"   (i.e. a pipe surrounded by double quotes). Sample data is below

 

NAME "|" HEIGHT "|" TITLE

 

TEVIN "|" 6'4 "|" FORWARD

 

When writing the infile statement, what should I put for the delimiter (DLM=) I've tried DLM='"|"" with no DSD and am getting funny results.

Any help you can provide would be much appreciated!

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It would be safer to switch to dlmstr= instead of dlm=.  Not knowing what might appear in your data, dlm= might have a flaw.  It would treat any pipe as a delimiter, whether or not it is surrounded by quotes.  So ....

 

 

infile source dsd dlmstr='"|"';

 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Hi @procsql 

 

data read_text;
if _n_=1 then k='"|"' ;
infile datalines  dlm=k;
input NAME $ HEIGHT $  TITLE : $10.;
cards;
TEVIN "|" 6'4 "|" FORWARD
;
novinosrin
Tourmaline | Level 20

or just

 

data read_text;
infile datalines  dlm='"|"';
input NAME $ HEIGHT $  TITLE : $10.;
cards;
TEVIN "|" 6'4 "|" FORWARD
TEVIN "|" 6'4 "|" FORWARD
TEVIN "|" 6'4 "|" FORWARD
;
Astounding
PROC Star

It would be safer to switch to dlmstr= instead of dlm=.  Not knowing what might appear in your data, dlm= might have a flaw.  It would treat any pipe as a delimiter, whether or not it is surrounded by quotes.  So ....

 

 

infile source dsd dlmstr='"|"';

 

procsql
Fluorite | Level 6

Thank you (and everyone else) who contributed to answering this question. You all are amazing!

I made one slight modification. Just used dlmstr='"|"' and removed the dsd part.  It worked perfectly. 

Tom
Super User Tom
Super User

Did you check if it is possible to have them create a more reasonable file?  It really looks like perhaps they did quite get the concept of a delimited file.

ballardw
Super User

If the data is not terribly sensitive then use a text editor to copy 10 or 15 lines or so and paste into a code box (important) opened using the forum's {I} icon.

 

If some of the data is sensitive then replace it with values like "XXXXXXX" and "YYYYYYY" for character values.

 

Did this project come with anything that described the data? Such as which fields should be numeric and character and what format/ length of values are supposed to be in the file? That is the first place to start.

 

By the way your example dlm has unbalanced quotes:

DLM ='"|"" 

You would want to use

DLMSTR = '"|"'

to use the whole value as a single delimiter.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 981 views
  • 8 likes
  • 5 in conversation