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

Hi all,

Would you know how I could read a CSV in which the delimiter as been set to a double pipe ('||') ? An empty value in this file would thus appear like 4 consecutive pipe ('||||'). We are still using the version 8 of SAS :smileylaugh:

I already know how to create such a file but not how to read it :smileyconfused:

Many thanks in advance for your help !

Kind regards,

Florent

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

hi ... I think that  _INFILE_ has been around since V8, so maybe ...

data x;

infile datalines dsd;

input @;

_infile_ = tranwrd(_infile_,'||',',');

input a b c;

datalines;

1||2||||

4||5||6

||8||||

;

a    b    c

1    2    .

4    5    6

.    8    .

ps ... some reading material ...

More _Infile_ Magic, Peter Crawford

http://www2.sas.com/proceedings/sugi28/086-28.pdf

Now _INFILE_ is an Automatic Variable − So What?, Howard Schreier,

http://www.nesug.org/proceedings/nesug01/cc/cc4018bw.pdf

View solution in original post

8 REPLIES 8
MikeZdeb
Rhodochrosite | Level 12

hi ... I think that  _INFILE_ has been around since V8, so maybe ...

data x;

infile datalines dsd;

input @;

_infile_ = tranwrd(_infile_,'||',',');

input a b c;

datalines;

1||2||||

4||5||6

||8||||

;

a    b    c

1    2    .

4    5    6

.    8    .

ps ... some reading material ...

More _Infile_ Magic, Peter Crawford

http://www2.sas.com/proceedings/sugi28/086-28.pdf

Now _INFILE_ is an Automatic Variable − So What?, Howard Schreier,

http://www.nesug.org/proceedings/nesug01/cc/cc4018bw.pdf

Florent
Quartz | Level 8

Thanks, it makes the job ! Smiley Wink

Astounding
PROC Star

Nice solution, but I'm not sure you should use dsd here.  The way I understood the data structure, a double delimiter indicates there is a blank variable.  If that's the case, dsd should become  dlm=','


MikeZdeb
Rhodochrosite | Level 12

hi ... DSD implies a few things:  a comma-delimiter; two consecutive commas indicate a missing value; considers delimiters within quotes as character data and strips quotes from quoted values

DLM=',' only does the comma-delimter portion

my example doesn't work with just DLM

Astounding
PROC Star

You're right, I'm temporarily brain-fried.  Sorry about that.

PGStats
Opal | Level 21

Hi, My concern would be that a file separated this way might contain commas in numeric or character fields.  It might be safer to keep the pipe character as in:

data x;

infile datalines delimiter='|' dsd;

input @;

_infile_ = tranwrd(_infile_,'||','|');

input (a b c) (:$);

datalines;

1||2,5||||

4||5||6

||8||||

;

PG

PG
data_null__
Jade | Level 19

I agree that changing the delimiter to comma might cause problem.  I would choose a character that is even more obscure.  Something untypeable perhaps.

PGStats
Opal | Level 21

The NUL character, of course! :smileylaugh:

PG

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1494 views
  • 3 likes
  • 5 in conversation