BookmarkSubscribeRSS Feed
Chikku
Calcite | Level 5

Hi all,

Please find the below sample data which is separated by pipe symbol(|).

i am not able to read this file.please help me in importing/reading the file.

regards,

karthik

/****************************samp.txt**************************************************/

NAME||AGE||SCORE_ENG||SCORE_ECO||SCORE_STAT||ROLL_NO||CLASS||RANK
AA||||12||||||15||||||20||||||25||||00||||X||||||1
BBB||||14||||||12||||||13||||||22||||01||||X||||||1
CC||||16||||||12||||||11||||||23||||02||||IX||||||1       
DD||||18||||||13||||||16||||||25||||03||||XI||||||1        
EEE||||13||||||14||||||14||||||05||||04||||X||||||1    
FFFFF||||17||||||16||||||16||||||14||||05||||XII||||||1

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why do you have two delimiters at each data item?  That's no longer a delimeted file.  Personally I would reject the file, and get the sender to provide a proper delimited file (i.e. data items separated by one character).  

What you have is going to make it quite hard to read in.  For instance the first line shows 8 variables, but the first data line:

AA||||12||||||15||||||20||||||25||||00||||X||||||1

Shows 7 data points, which one should be blank?  Is age 12 or missing?  Its a bit of a mess, and the responsibility of the file provider to sort it out.

Tom
Super User Tom
Super User

Looks like someone took a regular file and converted all of the spaces into two pipe characters.

Try using DLM='|' but without the DSD option.

data check;
  infile cards dlm='|' truncover ;
  length x1-x10 $50;
  input x1-x10;
cards;
NAME||AGE||SCORE_ENG||SCORE_ECO||SCORE_STAT||ROLL_NO||CLASS||RANK
AA||||12||||||15||||||20||||||25||||00||||X||||||1
BBB||||14||||||12||||||13||||||22||||01||||X||||||1
CC||||16||||||12||||||11||||||23||||02||||IX||||||1
DD||||18||||||13||||||16||||||25||||03||||XI||||||1
EEE||||13||||||14||||||14||||||05||||04||||X||||||1
FFFFF||||17||||||16||||||16||||||14||||05||||XII||||||1
;
proc print; run;
Ksharp
Super User

Delimiter is double pipe . You need TRANWRD() function .

 

 

 

data check;
  infile cards dlm='|' dsd truncover;
  input @;
  _infile_=tranwrd(_infile_,'||','|'); put _infile_;
  input (x1-x20) (:$10.);
cards;
NAME||AGE||SCORE_ENG||SCORE_ECO||SCORE_STAT||ROLL_NO||CLASS||RANK
AA||||12||||||15||||||20||||||25||||00||||X||||||1
BBB||||14||||||12||||||13||||||22||||01||||X||||||1
CC||||16||||||12||||||11||||||23||||02||||IX||||||1
DD||||18||||||13||||||16||||||25||||03||||XI||||||1
EEE||||13||||||14||||||14||||||05||||04||||X||||||1
FFFFF||||17||||||16||||||16||||||14||||05||||XII||||||1
;
proc print; run;
ballardw
Super User

This works for me on my machine with your text file:

filename t "d:\data\test.txt";

data junk;
   infile t dlmstr="||"  firstobs=2;
   informat name $5. age score_eng score_eco score_stat best8. roll_no class $4. rank $8.;
   input  name  age score_eng score_eco score_stat roll_no class rank ;
run;

However, you have a bunch of TABS at the end of the lines for Class IX XI and X, different numbers of tabs. Which is why I'm reading Rank as a string. It fails as a number because with the "delimiter" being "||" it attempts to read those tabs at the end as part of the value.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2882 views
  • 1 like
  • 5 in conversation