BookmarkSubscribeRSS Feed
lmitchell94
Calcite | Level 5

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 

 

 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Use PROC IMPORT selecting DBMS=TAB

--
Paige Miller
Astounding
PROC Star

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).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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