DATA Step, Macro, Functions and more

Modified List Input

Accepted Solution Solved
Reply
Senior User
Posts: 1
Accepted Solution

Modified List Input

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?

 

 

 


Accepted Solutions
Solution
‎05-25-2017 08:38 AM
Super User
Super User
Posts: 6,500

Re: Modified List Input

[ Edited ]

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


All Replies
Valued Guide
Posts: 797

Re: Modified List Input

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.

Solution
‎05-25-2017 08:38 AM
Super User
Super User
Posts: 6,500

Re: Modified List Input

[ Edited ]

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

 

Valued Guide
Posts: 797

Re: Modified List Input

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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