Reputation: 37
is there a solution for putting the select statement in brackets or something like this?
I need to perform this:
select t1.plz, t1.help, t1.me AS...
The Problem is, that my columns getting from a variable and my code perform this
select t1.plz, help, me
It works to the point i join it with an other table and the key gets mixed up. This works - t2.key, car,... but t2.car,key not, because i need to rename key as key2 and without the t2.key in front it doenst work...long story. I need to get that t1./t2. in front of every column.
Is there a solution for this problem?
My Code(SAS)
create table work.test as
select t1.&string1 t2.&string2
I can´t put the t1. in front of every string, because i perform a loop, so this would end in a t1.plz, t1.t1.help, t1.t1.t1,me.
Upvotes: 0
Views: 103
Reputation: 1804
Use the TRANWRD()
function to replace all the ", " with ", t1." then use SYMPUTX()
to create the macro variables.
The Code below will fix this for you by creating the macros with the correct prefix:
data _null_;
%let str1= "plz, help, me";
%let str2= "plz, help, me";
t1= cats('t1.',tranwrd(&str1,", ",", t1."));
t2= cats('t2.',tranwrd(&str2,", ",", t2."));
call symputx('string1',t1,'L');
call symputx('string2',t2,'L');
put _all_;
run;
Output: The two macros &string1 and &string2 will have the values below.
t1.plz, t1.help, t1.me
t2.plz, t2.help, t2.me
Upvotes: 2