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-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!

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
  • 3 replies
  • 1322 views
  • 2 likes
  • 3 in conversation