I have a file called BASEBALL.TXT
Here is one of the observation:
Ty Cobb, "Narrows, Georgia", The Georgia Peach
You submit this program
data scores;
infile BASEBALL.TXT dsd dlm=','
input Name :$20. Birthplace :$30. Nickname :$25.;
run;
The solution says for this particular observation the correct output is:
Ty Cobb, Narrows, Georgia, The Georgia Peach
My question is why did it remove the double quotes around Narrow, Georgia? Why is correct?
Because you used the DSD option.
The quotes in a CSV file are just there to allow consumers of the file to know that the embedded delimiter is part of the field value and NOT an indicaiton of the beginning of a new value. So SAS removes the quotes around values.
If you want actual quotes in the data field then you will need to quote the whole value.
Ty Cobb,"""Narrows, Georgia""",The Georgia Peach
Look up the section "modified list input" for the input statement. Especially use of the tilde (~) modifier. It's in SAS 9.4 Statements Reference book.
Because you used the DSD option.
The quotes in a CSV file are just there to allow consumers of the file to know that the embedded delimiter is part of the field value and NOT an indicaiton of the beginning of a new value. So SAS removes the quotes around values.
If you want actual quotes in the data field then you will need to quote the whole value.
Ty Cobb,"""Narrows, Georgia""",The Georgia Peach
It is because of the annoying need to triple the quotes wanted that I suggest learning about ~.
data scores;
infile datalines dlm=',' dsd;
input Name :~$20. Birthplace :~$30. Nickname :~$25.;
put (_all_) (/ =);
datalines;
Ty Cobb, "Narrows, Georgia", The Georgia Peach
Ty Cobb, 'Narrows, Georgia', The Georgia Peach
run;
The tilde format modifier is documented as
"reads delimiters within quoted character values as characters and retains the quotation marks".
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.