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
Use PROC IMPORT selecting DBMS=TAB
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).
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.