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


Hi Everyone,

I want to read a pipe-delimited file which consists of some values as dots.

Ex : Var1|Var2|Var3
         a   |b     |c
         d   |.      |e

         .    |f      |g

I have written the following program

data dummy;

infile "path\file.csv" dsd dlm="|" truncover LRECL=32767;

input var1 $char10. var2 $char10. var3 $char10.;

if _n_ = 1 then delete;

run;

But it is not working as expected. Can anyone please help me out. $char is considering default delimter as space. Can't we provide our own delimter?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data dummy;
infile cards dlm='|';
input var1 : $char10. var2 : $char10. var3 : $char10.;
if _n_ = 1 then delete;
cards;
 Var1|Var2|Var3
         a   |b     |c
         d   |.      |e
         .    |f      |g
;
run;

Ksharp

View solution in original post

3 REPLIES 3
Ksharp
Super User
data dummy;
infile cards dlm='|';
input var1 : $char10. var2 : $char10. var3 : $char10.;
if _n_ = 1 then delete;
cards;
 Var1|Var2|Var3
         a   |b     |c
         d   |.      |e
         .    |f      |g
;
run;

Ksharp

data_null__
Jade | Level 19

Your input statement is using "Formatted Input" (look it up).  Formatted Input is incompatible with delimited data.  You need to use "List Input" which is compatible.  You can use an informat with list input by using the : modifier.

Something like this.  Notice that $CHAR preserves leading spaces and read . as .;  You might like $F10.  which will read . as blank and left justify the values.

data dummy;
   infile cards dsd dlm="|" truncover;* LRECL=32767;
  
input (var1-var3)(:$char10.);
   cards;
Var1|Var2|Var3
   a   |b     |c
   d   |.      |e
   .    |f      |g
;;;;
   run;
data dummy2;
   infile cards dsd dlm="|" truncover;* LRECL=32767;
  
input (var1-var3)(:$10.);
   cards;
Var1|Var2|Var3
   a   |b     |c
   d   |.      |e
   .    |f      |g
;;;;
   run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1593 views
  • 2 likes
  • 3 in conversation