I have a macro variable
%let data =london paris;
The real variable is made by a sql into statment and will vary. What I want to do is to make a new macro variable datalist, which looks like this:
('london' , 'paris')
I am going to use this in where statment (old is a table which contains a city variable):
data new;
set old;
where city in &datalist;
run;
I have tried to make this variable in the following ugly way:
%let data =london paris;
%let datalist = (%str(%')%sysfunc(tranwrd(&data,%str( ),%str(%' , %')))%str(%'));
%put &datalist;
But when I run this code I got the following error message:
10 %let data =london paris;
11 %let datalist = (%str(%')%sysfunc(tranwrd(&data,%str( ),%str(%' , %')))%str(%'));
NOTE: Line generated by the macro function "SYSFUNC".
1 london' , 'paris
-----
49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding
identifier is recommended.
12 %put &datalist;
NOTE: Line generated by the macro variable "DATALIST".
1 ('london' , 'paris')
-----
49
('london' , 'paris')
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding
identifier is recommended.
What is really strange is that I can use this variable if I put in in a %unqote:
data new;
set old;
where city in %unquote(&datalist);
run;
But I still have this error message. Is there a better way of change the array variable from to:
paris london -> ('paris' , 'london')
SOLUTION The simple solution proposed by Quentin actually solved my problem
where findw("&datalist",trim(city)) ;
But the macro Quentin proposed also worked find but since I do not have any spaces in my variables (it is not cities in my dataset but sas column names) this simple solution is good enough.
QUOTE
actually do that though, or does it use"
instead? (I assume this is something that goes into a passthrough SQL query eventually) – Joecats("'",cityname,"'")
instead if I'm right aboutquote
. – Joe%Qsysfunc()
? Or does any macro quoting cause issues. – Tom