DATA Step, Macro, Functions and more

how to read character data that has quotation.

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

how to read character data that has quotation.

I have a code that read a text file, with delimiter pipe (|)

data sample;

Infile 'C:\mydata\test.txt' DSD  DLM='|'  LRECL=1024 MISSOVER  FIRSTOBS=1 TERMSTR=LF;

Input     fname :$CHAR20.

            lname :$CHAR30.

           city :$CHAR40.

run;

sample text file:

Jen|Turner|'Chicago'

David||'New York'

Michael|ybarra|Detroit

If I use DSD option ,SAS not  reading single quotes and consecutive delimiters reading as missing value...., Without DSD option SAS reads single quotes, but  consecutive delimiters are not reading as missed value.

Is there any infile options or a statement that reads single quotations in data and consider missing value for consecutive delimiter.? Thank you


Accepted Solutions
Solution
‎06-25-2015 12:54 AM
Respected Advisor
Posts: 4,934

Re: how to read character data that has quotation.

Use the tilde format modifier :

data sample;

length fname $20 lname $30 city $40;

Infile datalines dsd DLM='|' MISSOVER;

Input fname ~ lname ~ city ~;

datalines;

Jen|Turner|'Chicago'

David||'New York'

Michael|ybarra|Detroit

;

proc print data=sample; run;

PG

PG

View solution in original post


All Replies
Solution
‎06-25-2015 12:54 AM
Respected Advisor
Posts: 4,934

Re: how to read character data that has quotation.

Use the tilde format modifier :

data sample;

length fname $20 lname $30 city $40;

Infile datalines dsd DLM='|' MISSOVER;

Input fname ~ lname ~ city ~;

datalines;

Jen|Turner|'Chicago'

David||'New York'

Michael|ybarra|Detroit

;

proc print data=sample; run;

PG

PG
Contributor
Posts: 40

Re: how to read character data that has quotation.

Is there any other option without changing my entire code . Because I have 30 similar code with lot of  variables in input statement.

Super User
Posts: 10,044

Re: how to read character data that has quotation.

Code: Program

data sample;

Infile datalines dsd DLM='|' MISSOVER;
Input fname ~ : $20. lname ~ :$20. city ~ : $20.;
datalines;
Jen|Turner|'Chicago'
David||'New York'
Michael|ybarra|Detroit
;
run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 221 views
  • 4 likes
  • 3 in conversation