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".
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.