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

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
  • 4 replies
  • 1044 views
  • 7 likes
  • 3 in conversation