tags:

views:

38

answers:

1

A csv file I am trying to read with SAS has spaces between fields with double quotes.

example:

"ok","bad spaces ahead"        ,"more data"  
_______________________^spaces^____________  


How do I get SAS to read this correctly? Do I need to have the csv replaced?

+2  A: 

adding dsd and missover in your infile statement works?

data badspaces;
    infile datalines dlm=',' dsd missover;
    format Var1 $2.
        Var2 $20.
        Var3 $10.;
    input var1-var3;
    put 'x' var1 'x'
    /   'x' var2 'x'
    /   'x' var3 'x'
    /;
datalines;
"ok","bad spaces ahead"        ,"more data"
"ok","no spaces ahead","more data"
run;

from the log:

xok x
xbad spaces ahead x
xmore data x

xok x
xno spaces ahead x
xmore data x
rkoopmann
You can remove the unwanted space in the log by using the pointer control like so: `put "***" var1 +(-1) "***";` which will print out: `***ok***`
Chang Chung