Help using Base SAS procedures

Reading period from a delimited file using Char$ informat

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Reading period from a delimited file using Char$ informat


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?


Accepted Solutions
Solution
‎06-24-2013 06:08 AM
Super User
Posts: 9,671

Re: Reading period from a delimited file using Char$ informat

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


All Replies
Solution
‎06-24-2013 06:08 AM
Super User
Posts: 9,671

Re: Reading period from a delimited file using Char$ informat

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

Occasional Contributor
Posts: 7

Re: Reading period from a delimited file using Char$ informat

Thank You Smiley Happy

Respected Advisor
Posts: 3,777

Re: Reading period from a delimited file using Char$ informat

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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