I would like to use estimate value to create a macro variable aa when the wk in data2 matches the wk2 in data1.
The where condition in PROC SQL does not work properly.
Any way to solve this? Thanks.
data data1;
input wk2 estimate;
datalines;
1 12
2 14
3 15
;
run;
%macro trash(var1=, var2=);
%global &var2;
proc sql;
select distinct estimate into: &var2
from summ
where wk2=&var1;
quit;
%mend trash;
data data2;
wk=2;
%trash(var1=wk,var2=aa);
%put &aa;
run;
proc print data=ori;run;
use Call execute() .
works. Any other methods to do this?
From your example, it seems unnecessary to create data2:
data _null_
set data1;
where ws = '2';
call symput('AA',estimate);
run;
Is ws unique in data1?
What do you intend to use &AA for?
data data1;
input wk2 estimate;
datalines;
1 12
2 14
3 15
;
run;
data j;
set data1;
if wk2=2 then call symputx("aa", estimate);
run;
Automatically Macro variables created in Call symputx will be global. if you use this out of %macro %mend;
I think it's working by using WHERE clause in proc sql
proc sql noprint;
select estimate into :aa
from data1 as a,
data2 as b,
where a.wk2 = b.wk;
quit;
%put &aa.;
-Urvish
Do you expect process to execute the way it was laid out with indentation - with the sql macro executing within the data step?
A feature being introduced with SAS9.4 (next month) will allow something like that. However you are not using the relevant syntax.
Check out the function DOSUBL() at support.sas.com
peterC
Hi,
data data1;
input wk2 estimate;
datalines;
1 12
2 14
3 15
;
run;
%macro Test (num=);
proc sql noprint;
select estimate into : aa from data1
where wk2=#
quit;
%put &aa;
data data2;
wk=#
estimate=&aa;
run;
proc print;run;
%mend Test;
/* calling the macros */
%test(num=2);
%test(num=3);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.