11-07-2016 03:54 AM
I created a flag variable like the below
where visitnum gt 3;
if dastresn gt 0 then do; FLAG="Y"; FLAGN=1; end;
if dastresn le 0 then do; FLAG="N"; FLAGN=0; end;
Now for some subjs i get both Y and N and in those cases i only need Y.
I used nodupkey to get unique subjects but in some subjects i get flag as N
11-07-2016 04:03 AM
sub visit flag
1 3 Y
1 4 Y
2 4 N
2 5 N
2 6 Y
3 4 Y
In the above if i want unique sub i do nodupkey on sub but for sub 2 the flag is N and Y and i only get N as it is first. FOr sub 2 i want Y if it has both N and Y
11-07-2016 04:14 AM
Thats not a nodupkey then, nodupkey removes duplicate information based on the by grouping. Yours is a logical problem. I would say (and as there is no test data in the form of a datastep this is just theory):
sort your data with your flag in descending order on flag
do a datastep by subjid, if last.subjid then output
This way if Y exists it will be first.subjid due to the sort, otherwise N will be there.
11-07-2016 04:29 AM
proc sort data=have; by sub flag; run; data want; set have; by sub; if last.sub; run;
Since 'Y' comes after 'N' in the sort order, this gets what you want.
If you want the last visit where flag was 'Y', add visit to the by statement in the sort.