UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS FAQ 
How do I read a delimited file that has embedded delimiters in the data?

Suppose you are reading a comma separated file, but your data contains commas in it. For example, say your file contains age name and weight and looks like the one below.

48,'Bill Clinton',210
50,'George Bush, Jr.',180

Say you read this file as you would any other comma delimited file, like the example shown below.

 DATA guys1;
  length name $ 20 ;
  INFILE 'readdsd2.txt' DELIMITER=',' ;
  INPUT age name weight ;
RUN;
 
PROC PRINT DATA=guys1;
RUN;

But, as we see below, the data were not read as we wished. The quotes are treated as data, and George Bush lost the , Jr off his name, and his weight is missing. This is because SAS treated the , in George Bush's name as a indicating the end of the variable, which is not what we wanted.

OBS         NAME         AGE    WEIGHT
1     'Bill Clinton'     48      210
2     'George Bush       50        .

Below, we use the dsd option to read the same file.

DATA guys2;
  length name $ 20 ;
  INFILE 'readdsd2.txt' DELIMITER=',' DSD ;
  INPUT age name weight ;
RUN;
 
PROC PRINT DATA=guys2;
RUN;

As you see in the output below, SAS properly treated the quotes as delimiters, and it read in Mr. Bush's name properly and his weight properly.

OBS          NAME          AGE    WEIGHT

 1     Bill Clinton         48      210
 2     George Bush, Jr.     50      180

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California