Hi,
I need to read Delimited Text Files into SAS.
The delimiter is a single blank (delimiter='20'x).
My problem is that blank that are protected by "" are not a delimiter.
Example:
Fabio USA "San Francisco"
must be:
var1=Fabio
var2=USA
var3="San Francisco"
Thank you very much for your help.
Fabio
Because the quotes are not around the full value of the field.
data a;
infile cards dsd dlm=' ' truncover;
length var1-var3 $100 ;
input var1-var3;
put (var1-var3) (=/);
cards4;
Fabio USA "San Francisco"
test user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)" x
test "user-agent=""Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)""" y
;;;;
You could try using the SCAN() function to parse the line yourself.
data a;
infile cards dsd dlm=' ' truncover;
length var1-var3 $100 ;
array v var1-var3 ;
input ;
do i=1 to 3; v(i)=dequote(scan(_infile_,i,' ','QM')); end;
put (var1-var3) (=/);
cards4;
Fabio USA "San Francisco"
test user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)" x
test "user-agent=""Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)""" y
;;;;
Use the DSD option.
data a;
infile cards dsd dlm=' ' truncover;
length var1-var3 $20 ;
input var1-var3;
put (var1-var3) (=/);
cards;
Fabio USA "San Francisco"
;;;;
Thank you Tom!
But reading this txt:
test user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)"
with you code I don't have
var1= test
var2= user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)"
but
var1= test
var2= user-agent="Mozilla/4.0
var3= (compatible;
....
Why?
Thank you very much
Because the quotes are not around the full value of the field.
data a;
infile cards dsd dlm=' ' truncover;
length var1-var3 $100 ;
input var1-var3;
put (var1-var3) (=/);
cards4;
Fabio USA "San Francisco"
test user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)" x
test "user-agent=""Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)""" y
;;;;
You could try using the SCAN() function to parse the line yourself.
data a;
infile cards dsd dlm=' ' truncover;
length var1-var3 $100 ;
array v var1-var3 ;
input ;
do i=1 to 3; v(i)=dequote(scan(_infile_,i,' ','QM')); end;
put (var1-var3) (=/);
cards4;
Fabio USA "San Francisco"
test user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)" x
test "user-agent=""Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;)""" y
;;;;
Fabio
If that is the conmon structure of your data, use that= as delimiter as well as blank.
OK it separates names from values, but you know about that.
In this way
DLM= ' ='
Then either blank or equals would be used as delimiters. Your data provider appears to be properly qualifying (quoting) the values that contain blanks so the DSD option will properly handle those.
Good luck
peter.C
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.