Solved
Not applicable
Posts: 1

# Quatation Marks

Hi, I want to add Quatation marks around the below data like it is in the Address when i export the data to external file.

data customers;

length name \$ 20 address \$ 60;

infile datalines dsd;

input name \$ address \$ age;

datalines;

John,"23 Jacaranda Street,Pretoria,South Africa",45

Mary,"985 Bay Avenue,Cape Town,South Africa",31

Lee-Ann,"89 Church,Rustenburg,South Africa",65

;

run;

Regards

Job

Accepted Solutions
Solution
‎08-06-2013 06:06 AM
Contributor
Posts: 25

## Re: Quatation Marks

Hi Job,

Try the following, I am sure there will be other solutions but this is the quickest one I can think of.

In the file and datafile= statement please just remember to put your URL in when testing.

data _null_;

file 'test.csv' dlm=",";

set customers(rename=(age=temp_age));

name = cats('"',name,'"');

age = cats('"',temp_age,'"');

if _n_ = 1 then put 'name,address,age';

run;

proc import datafile='test.csv' dbms=csv replace out=imported;

run;

All Replies
Solution
‎08-06-2013 06:06 AM
Contributor
Posts: 25

## Re: Quatation Marks

Hi Job,

Try the following, I am sure there will be other solutions but this is the quickest one I can think of.

In the file and datafile= statement please just remember to put your URL in when testing.

data _null_;

file 'test.csv' dlm=",";

set customers(rename=(age=temp_age));

name = cats('"',name,'"');

age = cats('"',temp_age,'"');

if _n_ = 1 then put 'name,address,age';

run;

proc import datafile='test.csv' dbms=csv replace out=imported;

run;

Super Contributor
Posts: 644

## Re: Quatation Marks

There is a quote() function that wraps quotes around a text variable.  You may need to use it with trim() to remove trailing blanks, so the cats() approach may be just as efficient.  Remember that when you enclose a value with quotes you increase the length by 2 bytes.  If any of your values have a length equal to the variable length the value will be truncated and worse still you will have unmatched quotes.  To ensure this does not happen, ensure lengths for name and address have extra space.

Richard

Super User
Posts: 8,090

## Re: Quatation Marks

Are you talking about generating a text file or a SAS dataset?

For the SAS dataset you can tell the INPUT statement to preserve the surrounding quotes by using the ~ input modifier.

input name ~ address ~ age;

For an output file if you should play with different combinations of the DSD option, \$QUOTE. format and the ~ modifier on the PUT function.

🔒 This topic is solved and locked.