DATA Step, Macro, Functions and more

how to take off double quotes from character variable while exporting it into CSV file

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

how to take off double quotes from character variable while exporting it into CSV file

Hi All,

When I  export my sas dataset to csv file. I notice that for character variable containing Address string automatically comes up with double quotes. While some records have quotes rest of the addresses don't have quotes.

 

For example:

address

" Unit 4, 103 apartment name"

2/3 some road name

 

I want the addresses without quotes. I use Export procedure to get the dataset into CSV file. I wonder if there is any way  , i can avoid getting quotes in CSV file.

 

Just to be clearer my sas dataset doesn't contain single or double quotes.

 

Thanks,

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 23,245

Re: how to take off double quotes from character variable while exporting it into CSV file

Posted in reply to sas_learnsups

Look at that address. It has a comma embedded, so if you export it like that to a CSV, how do you know where the delimiter is?

That row will have an extra comma which will cause all kinds of issues, so the convention is to add quotes and the comma in the quotes is ignored. Don't remove them.

 

If you really, really want to, you can use PUT statements instead which allows you to control it explicitly. 

 


@sas_learnsups wrote:

Hi All,

When I  export my sas dataset to csv file. I notice that for character variable containing Address string automatically comes up with double quotes. While some records have quotes rest of the addresses don't have quotes.

 

For example:

address

" Unit 4, 103 apartment name"

2/3 some road name

 

I want the addresses without quotes. I use Export procedure to get the dataset into CSV file. I wonder if there is any way  , i can avoid getting quotes in CSV file.

 

Just to be clearer my sas dataset doesn't contain single or double quotes.

 

Thanks,

 


 

View solution in original post


All Replies
Solution
2 weeks ago
Super User
Posts: 23,245

Re: how to take off double quotes from character variable while exporting it into CSV file

Posted in reply to sas_learnsups

Look at that address. It has a comma embedded, so if you export it like that to a CSV, how do you know where the delimiter is?

That row will have an extra comma which will cause all kinds of issues, so the convention is to add quotes and the comma in the quotes is ignored. Don't remove them.

 

If you really, really want to, you can use PUT statements instead which allows you to control it explicitly. 

 


@sas_learnsups wrote:

Hi All,

When I  export my sas dataset to csv file. I notice that for character variable containing Address string automatically comes up with double quotes. While some records have quotes rest of the addresses don't have quotes.

 

For example:

address

" Unit 4, 103 apartment name"

2/3 some road name

 

I want the addresses without quotes. I use Export procedure to get the dataset into CSV file. I wonder if there is any way  , i can avoid getting quotes in CSV file.

 

Just to be clearer my sas dataset doesn't contain single or double quotes.

 

Thanks,

 


 

Occasional Contributor
Posts: 13

Re: how to take off double quotes from character variable while exporting it into CSV file

ohh! I get that now! Thanks for quick response.
PROC Star
Posts: 2,311

Re: how to take off double quotes from character variable while exporting it into CSV file

Posted in reply to sas_learnsups

Function dequote() does what you want. 

But as said above, what you want is not what you need.

Occasional Contributor
Posts: 13

Re: how to take off double quotes from character variable while exporting it into CSV file

Thanks Chris, I got the point.
PROC Star
Posts: 1,564

Re: how to take off double quotes from character variable while exporting it into CSV file

Posted in reply to sas_learnsups

@sas_learnsups  Sir/Madam, It would be more encouraging if you could rather  mark @Reeza as the accepted solution for the very intuitive detailed reasoning. We then community(you included) feel encouraged with such responses to delve more and more with interesting responses. Just a thought. Sorry for the bother. Thank you!

Occasional Contributor
Posts: 13

Re: how to take off double quotes from character variable while exporting it into CSV file

Posted in reply to novinosrin
Well I thought i marked her response as Solution but my reponses got marked. It wasnt intentional. Thanks though for pointing it out to me.
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 142 views
  • 2 likes
  • 4 in conversation