Hi,
Added few details below
I have a ctrl dataset which has the following structure
Ctrl
seq_num A condn B
1 A1 eq B1
1 A2 le B2
1 A3 ge B3
2 A4 le B4
3 A5 ge B5
3 A6 eq B6
I have created a macro createjoin() which sorts this dataset by id creates the following condition from this data set
CONDITION1 if a1 eq b1 and a2 le b2 and A3 ge b3 ;
CONDITION 2 if a4 le b4;
Condition 3 if A5 ge B5 and a6 eq b6;
The code is as follows
%macro m_createjoins(mv_seq_num);
/*Sort the dataset*/
proc sort data=input.ctrl;
by seq_num;
run;
data input.ctrl_mod;
set input.ctrl;
where seq_num = mv_seq_num;
/*Create the joining condition, count and store it in macrovariables*/
data _null_;
length jstmt $400;
set input.ctrl_mod; end=eof;
by seq_num;
if first.seq_num then
do;
jstmt=' ';
jstmt=catx(' ','if',A,condition,B);
end;
if first.seq_num = 0 then
jstmt=catx(' ',jstmt,'and (',A,condition,B,')');
if last.seq_num then
do;
jstmt=catx(' ',jstmt,'then','do',';');
put jstmt=;
flag+1;
call symputx('m_join_condition',jstmt,'g');
end;
retain jstmt;
if eof then
estmt =cats (' ', 'end',';');
call symputx('m_estmt',estmt,'g');
run;
%mend m_createjoins;
I am trying to use this macro in the following merge
data A;
input id rs xxx code ;
datalines;
1 34 0 10
2 34 0 10
3 20 0 30
;
run;
data B;
input id rev code ;
datalines;
1 34 0 20
2 34 0 30
3 20 0 10
;
run;
proc sort data=a;
by code;
run;
proc sort data=b;
by code;
run;
/*here i am trying to pass the value of id to the macro create join and create the conditions for the corresponding id each time i call the macro */
%macro temp;
data C;
merge A B;
by code;
if rs= 34 then
do;
if id =1 then
do;
%m_createjoins(1);
&&m_join_condition
xxx=123;
&m_estmt
end;
end;
run;
%mend temp;
%temp;
I am getting errors probably due to the timing of macro variables resolution. Is there any way i can call the macro from the datastep by passing the parameter , generate only the appropriate condition and get the condition in the do loop?
When i modified the code for the macro temp , it is working fine. Here i executed the macro once for all and created the condition , stored it in the macro variables starting from 1 to n and substituting the condition.
%macro temp;
data B;
set A;
if rs= 34 then
do;
if id =1 then
do;
&&rm_join_condition1
xxx=123;
&m_estmt
end;
else if id =2 then
do;
&&rm_join_condition2
&m_estmt
end;
end;
run;
%mend temp;
%temp;
Is there any way i can call the macro to generate only the condition which i require at that point?
Appreciate any help.
Thanks in advance,
Regards,
Sheeba
... View more