1

I am reading in a text file where 2 character variables both have a value of an apostrophe ' separated by a comma delimiter in di studio. Di is reading it as the apostrophes are masking the comma, taking the comma as the value rather than the apostrophes as the value.

An example of the record looks like

    95,',',,,word

This should give me:

    Var1 = 95
    Var2 = '
    Var3 = '
    Var4 = .
    Var5 = .
    Var6 = word

Instead I get:

    Var1 = 95
    Var2 = ,
    Var3 = .
    Var4 = .
    ...

What informats do I need to use or options do I need to set other than delimiter set to a comma? (Di options preferably, but base SAS options would help as well). Thanks in advance.

1 Answers1

0

Make sure that you are not using the dsd option on your infile statement. Provided that none of the character variables ever contain commas, something like the following should work:

data want;
infile cards dlm=',' missover;
input var1 :8. (var2-var6) (:$4.);
cards;
95,',',,,word
;
run;

If the character variables in your file do occasionally contain commas and they are not quoted, there may be no consistent way to read your file.

user667489
  • 9,501
  • 2
  • 24
  • 35
  • Good afternoon user667488, many thanks for your reply as I am very grateful. The problem is that some other variables genuinely have a single apostrophe in the data. I have tried doing it without DSD and it causes issues as it then does not read in the missing values when their are consecutive delimiters. Much appreciated. – Trying to SAS Mar 01 '17 at 15:40
  • Please update your question to provide an example seen in your data where this approach doesn't work. – user667489 Mar 01 '17 at 16:05