Can you help me in solving problem below. I am providing here the appropriate ancestor for each of the record. I need to find this ancestor for each of the record by user. Can you please help.
data a;
user=1; base=4.1; cur=4.2; output; /* 4.1 to 4.2 - Ancestor here is 4.4 */
user=1; base=4.2; cur=4.4; output; /* 4.2 to 4.4 - Ancestor here is 4.4 */
user=1; base=4.6; cur=5.5; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */
user=1; base=5.5; cur=6.1; output; /* 5.5 to 6.1 - Ancestor here is 6.1 */
user=2; base=4.2; cur=4.6; output; /* 4.2 to 4.6 - Ancestor here is 6.1 */
user=2; base=4.6; cur=5.5; output; /* 4.6 to 5.5 - Ancestor here is 6.1 */
user=2; base=5.5; cur=6.1; output; /* 5.0 to 6.1 - Ancestor here is 6.1 */
user=3; base=4.0; cur=4.2; output; /* 4.0 to 4.2 - Ancestor here is 5.5 */
user=3; base=4.2; cur=4.6; output; /* 4.2 to 4.6 - Ancestor here is 5.5 */
user=3; base=4.6; cur=5.5; output; /* 4.6 to 6.1 - Ancestor here is 5.5 */
run;
I am able to achieve this if there is only one user in the dataset using code below. But its not working if there are more than one user.
data _tmp1(rename=(base=base1 cur=cur1));
set a;
run;
**Repeat the training module for each of the delta version between base and current module;
data _tmp2;
retain base cur;
set _tmp1; by u;
cur = cur1;
base = base1;
output;
drop base1 cur1 i;
run;
**Get all the base version for the current modue which has training then need to check the
corresponding base version full access;
data _lineage;
set _tmp2; by u;
array hist(6);
count=1;
hist(count)=base;
do i=1 to last while (count<dim(hist)-1);
set _tmp2(rename=(base=base1 cur=cur1)) nobs=last point=i;
if cur=base1 then do;
count+1;
hist(count)=base1;
base=base1;
cur=cur1;
i=1;
end;
end;
count+1;
hist(count)=cur;
ancest = cur;
run;
... View more