BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
adennis8872
Calcite | Level 5

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?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

 

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

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

 

mkeintz
PROC Star

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

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1249 views
  • 3 likes
  • 3 in conversation