How to convert .txt data to SAS dataset

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

How to convert .txt data to SAS dataset

Hi

I have txt file like this.The variables name flight number,codes1,codes2,codes3,codes4, destination(Delhi) ,stopover (Melbourne),scheduled, estimated,terminal,status.

If you look at data (scheduled, estimated,terminal)  all together in single line.

Plz guide me to create a syntax for this data.

AI301

Delhi/Melbourne

7:45 am 8:18 am T1

Departed

KE122

OK3357

Seoul/Incheon

7:45 am 8:03 am T1

Departed

EK412

QF8764

Auckland

7:50 am 7:51 am T1

Departed

SQ212

VS7212

VA5508

TK7905

Singapore

7:55 am 8:05 am T1

Departed

Thank you

Attachment

Accepted Solutions
Solution
‎05-07-2015 07:53 AM
Super User
Posts: 9,867

Re: How to convert .txt data to SAS dataset

The only thing left is to rename the variable's name. I think it is easy for you to done , right ?

View solution in original post


All Replies
Super User
Posts: 9,867

Re: How to convert .txt data to SAS dataset

This could give you a start.

data have;
infile cards truncover;
input x $100.;
if prxmatch('/^\s/',x) then do;n+1;delete;end;
if anydigit(x) not in (0 1) then z=0;else z=1;
cards;
AI301
Delhi/Melbourne
7:45 am 8:18 am T1
Departed
 
KE122
OK3357
Seoul/Incheon
7:45 am 8:03 am T1
Departed
 
EK412
QF8764
Auckland
7:50 am 7:51 am T1
Departed
 
SQ212
VS7212
VA5508
TK7905
Singapore
7:55 am 8:05 am T1
Departed
;
run;
data x;
 set have;
 by n z notsorted;
 length pre $ 10;
 if first.z then count=0;
 count+1;
 if z=0 then pre=cats('a',count);
  else pre=cats('b',count);
run;
proc transpose data=x out=y(drop=_:);
by n;
id pre;
var x;
run;

Xia Keshan

New Contributor
Posts: 3

Re: How to convert .txt data to SAS dataset

Thank you Xia Keshan,

Please let me know any other input for this question.

Thank you

Solution
‎05-07-2015 07:53 AM
Super User
Posts: 9,867

Re: How to convert .txt data to SAS dataset

The only thing left is to rename the variable's name. I think it is easy for you to done , right ?

New Contributor
Posts: 3

Re: How to convert .txt data to SAS dataset

Thank you Xia Keshan

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 309 views
  • 2 likes
  • 2 in conversation