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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

;;;;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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"

;;;;

Fabio
Calcite | Level 5

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

Tom
Super User Tom
Super User

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

;;;;

Peter_C
Rhodochrosite | Level 12

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1818 views
  • 7 likes
  • 3 in conversation