Reputation: 521
For instance, I have 2 macro variables ....
%let A = ('a','b','c');
%let B = ('d','e','f');
I'm trying to create a new macro variable from above 2 macro variables..
%let c = ('a','b','c','d','e','f');
I tried %let c = (&A,&B);
Upvotes: 1
Views: 1495
Reputation: 705
If you are the one who is defining A and B, you could just remove the brackets when defining the two variables.
%let A = 'a','b','c';
%let B = 'd','e','f';
%let C = (&A,&B);
%PUT &C ;
Result from log - ('a','b','c','d','e','f')
Joe... isn't this simpler?
Upvotes: 4
Reputation: 63424
While it's possible to combine them as Chris J shows, the better answer is not to store them this way. If you're storing them with parentheses because you will use them later in a situation where parentheses are needed, simply provide them then.
%let A = 'a','b','c';
%let B = 'd','e','f';
%let C = &a,&b;
data want;
set have;
if a in (&a) or b in (&b) or c in (&c) then do;
output;
end;
run;
Much simpler code that way.
Upvotes: 3
Reputation: 7769
Use the compress() function within a %SYSFUNC to remove the parentheses from A and B...
You need to use %( and %) to represent the parentheses and prevent them from being interpreted as the closure of the %SYSFUNC.
%LET A = ('a','b','c') ; %LET B = ('d','e','f') ; %LET A2 = %SYSFUNC(compress(&A,%(%))) ; %LET B2 = %SYSFUNC(compress(&B,%(%))) ; %LET C = (&A2,&B2) ; /* or all in one... */ %LET C = (%SYSFUNC(compress(&A,%(%))),%SYSFUNC(compress(&B,%(%)))) ; %PUT &C ; Macro variable C resolves to ('a','b','c','d','e','f')
Incidentally, if you intend on using &C in an in() condition, it will work as-is, i.e.
%LET A = ('a','b','c') ; %LET B = ('d','e','f') ; %LET C = (&A,&B) ; data test ; letter = 'd' ; exist = letter in &C ; /* resolves to (('a','b','c'),('d','e','f')) */ run ;
Upvotes: 4