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