DATA Step, Macro, Functions and more

Reading comma Delimited File

Reply
Frequent Learner
Posts: 1

Reading comma Delimited File

I'm trying to the read the following data from a text file into a data set and proc print it. 

East Caribbean,799,1514,1335
East Caribbean,1068,2319,1864
East Caribbean,899,999,967
East Caribbean,1240,899,769
East Caribbean,1100,1769,1044
West Caribbean,1018,1065,907
West Caribbean,999,1118,959
West Caribbean,865,815,499
West Caribbean,799,755,529
West Caribbean,832,999,782
South Caribbean,1293,1101,918
South Caribbean,1763,1999,1023
South Caribbean,939,968,895
South Caribbean,770,778,708
South Caribbean,861,1751,954

The code I've written is

Data Cruises2;
infile '/home/lam13h/Data/Cruises2.txt/' dlm=',';
length Itinerary $ 15;
input Itinerary $ &
Princess
RoyalCaribbean
Carnival;
run;

proc print data=cruises2;
run;

 

However it isn't reading the data correctly and keeps including commas with the first data column and not including the data in the last 3 columns. I've tried everything I can think of and can't get this to work. Please help 

 

 

 

Trusted Advisor
Posts: 1,913

Re: Reading comma Delimited File

Posted in reply to lmitchell94

Use PROC IMPORT selecting DBMS=TAB

Super User
Posts: 5,498

Re: Reading comma Delimited File

Posted in reply to lmitchell94

The problem is this combination:

 

dlm=','

$ &

 

The & tells SAS to keep reading until it finds two consecutive delimiters.  In this case, that would be two consecutive commas.  Just remove the & and that should work for the limited amount of data that you illustrated.  If there are other issues, other measures might need to be taken (including the possibility that was already mentioned about switching to PROC IMPORT).

Ask a Question
Discussion stats
  • 2 replies
  • 164 views
  • 0 likes
  • 3 in conversation