@MohitDamani wrote: i need combination of both variables like we do partition by in SQL, for eg row 1,3,5 & 7 should have 1 rest 0
A slight expansion of @PeterClemmensen's code shows that it clearly works:
data have;
input id1 id2;
n = _n_;
datalines;
1001 10
1001 10
1001 11
1001 10
1002 12
1002 12
1002 13
;
run;
proc sort data = have;
by id1 id2;
run;
data want;
set have;
by id1 id2;
if first.id2 then first_unique = 1;
else first_unique = 0;
run;
proc print data=want noobs;
run;
Result:
first_
id1 id2 n unique
1001 10 1 1
1001 10 2 0
1001 10 4 0
1001 11 3 1
1002 12 5 1
1002 12 6 0
1002 13 7 1
If you need the original order restored, just sort by n.
... View more