BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Vestax
Calcite | Level 5

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. 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

@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

6 REPLIES 6
novinosrin
Tourmaline | Level 20

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 ;
Vestax
Calcite | Level 5

@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? 

Reeza
Super User

Any reason you can’t do this instead:

 

select &team as members....

Vestax
Calcite | Level 5
The PROC SQL doesn't like that there multiple double quotes. After the second double quote, it errors out.
novinosrin
Tourmaline | Level 20

@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.

 

 

 

Vestax
Calcite | Level 5
This works as intended. Thanks for your help.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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