Guys, I am doing a concatenation reading data one observation at a time. So my data and code is as follows: data have; input @1 label1 $ @3 label2 $ @5 label3 $1. @7 condition $; cards; a d p code1 a d p code7 b e q code2 b e q code3 c p code4 d a r code5 d a r code6 ; run; options nomlogic ; %macro rules (table_name); /* open the table*/ %let table_id=%sysfunc(open(&table_name,i)); /* fetch the first record */ %let rc=%sysfunc(fetch(&table_id)); %if &rc ne 0 %then %do; %put something is wrong ...; %end; %else %do; /* read data for first record */ %let label1=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label1)))); %let label2=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label2)))); %let label3=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label3)))); %let condition=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,condition)))); /* Save values and iterate again */ %let prev_label1=&label1; %let prev_label2=&label2; %let prev_label3=&label3; %let prev_condition=&condition; /* Read remaining records */ %let rc=%sysfunc(fetch(&table_id)); %do %while (&rc eq 0); %let label1=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label1)))); %let label2=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label2)))); %let label3=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,label3)))); %let condition=%sysfunc(getvarc(&table_id, %sysfunc(varnum(&table_id,condition)))); %if (&prev_label1 eq &label1)and (&prev_label2 eq &label2) and (&prev_label3 eq &label3) %then %do; %let new_condition=case when &prev_condition or (&condition); %put new_condition is &new_condition; %end; %else %do; %let prev_label1=&label1; %let prev_label2=&label2; %let prev_label3=&label3; %let prev_condition=&condition; %let new_condition=case when &prev_condition or (&condition); %end; %put new_condition is &new_condition; %let rc=%sysfunc(fetch(&table_id)); %end; %let rc=%sysfunc(close(&table_id)); %end; %mend; %rules(have); What i want in output is new_condition is case when ((code1) or (code7)) new_condition is case when ((code2) or (code3)) new_condition is case when ((code2) or (code3)) new_condition is case when ((code4)) new_condition is case when ((code5) or (code6)) However, my last observation and first observation gets lost in loop. Please share your views.. Thanks in advance
... View more