How to remove multiple double quotes in a macro variable?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How to remove multiple double quotes in a macro variable?

Hi all. We have a list of emails that I'm trying to store in a table that looks something like this:

 

"ironman@marvel.com" "thor@marvel.com" "hulk@marvel.com"

 

which is passed onto a macro var &team. It is then called out in a proc sql that looks like this:

 

proc sql;

create table avengers as

select

"&team." as members

from earth

;

quit;

 

However SAS sees the double quotes and gets all confused. It won't let me use single quotes. I've tried compress and tranwrd, those are not working either. Any help is appreciated. 

 

 

 


Accepted Solutions
Solution
2 weeks ago
Super User
Posts: 2,061

Re: How to remove multiple double quotes in a macro variable?

@Vestax have you tried translate instead of trnwrd?

 


%let k="ironman@marvel.com""thor@marvel.com""hulk@marvel.com";
%put &k;
%let k1=%sysfunc(translate(%superq(k),%str( ),%str(%")));
%put &k1 ;

 

I think somebody who is senior and wiser  would prolly even suggest a better design of the data flow process or even table design. The manual operation seems wary. But anyway up to you.

 

 

 

View solution in original post


All Replies
Super User
Posts: 2,061

Re: How to remove multiple double quotes in a macro variable?

Not sure, as I don't comprehend the flow of data in your process but a simple demo

 

%let k="ironman@marvel.com" "thor@marvel.com" "hulk@marvel.com";
%put &k;
%let k1=%sysfunc(compress(%superq(k),%str(%")));
%put &k1 ;
New Contributor
Posts: 4

Re: How to remove multiple double quotes in a macro variable?

[ Edited ]
Posted in reply to novinosrin

@novinosrin wrote:

Not sure, as I don't comprehend the flow of data in your process but a simple demo

 

%let k="ironman@marvel.com" "thor@marvel.com" "hulk@marvel.com";
%put &k;
%let k1=%sysfunc(compress(%superq(k),%str(%")));
%put &k1 ;

 

We're trying to store the string in the macro variable as an observation. Your solution works somewhat but what if there are no spaces and the data coming in looks like 

%let k="ironman@marvel.com""thor@marvel.com""hulk@marvel.com";

Is it possible to add spaces or remove the double quotes without compressing the spaces? 

Super User
Posts: 24,012

Re: How to remove multiple double quotes in a macro variable?

Any reason you can’t do this instead:

 

select &team as members....

New Contributor
Posts: 4

Re: How to remove multiple double quotes in a macro variable?

The PROC SQL doesn't like that there multiple double quotes. After the second double quote, it errors out.
Solution
2 weeks ago
Super User
Posts: 2,061

Re: How to remove multiple double quotes in a macro variable?

@Vestax have you tried translate instead of trnwrd?

 


%let k="ironman@marvel.com""thor@marvel.com""hulk@marvel.com";
%put &k;
%let k1=%sysfunc(translate(%superq(k),%str( ),%str(%")));
%put &k1 ;

 

I think somebody who is senior and wiser  would prolly even suggest a better design of the data flow process or even table design. The manual operation seems wary. But anyway up to you.

 

 

 

New Contributor
Posts: 4

Re: How to remove multiple double quotes in a macro variable?

Posted in reply to novinosrin
This works as intended. Thanks for your help.
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 137 views
  • 0 likes
  • 3 in conversation