data have1;
infile datalines dsd dlm=",";
input usubjid $ visit $ glaucoma $ glaucoma_r $ glaucoma_l $ target_eye;
datalines;
001, a, , Y, N, 2
001, b, Y, , , 2
001, c, Y, , , 2
001, d, Y, , , 2
001, e, N, , , 2
002, a, , N, Y, 1
002, b, Y, , , 1
002, c, Y, , , 1
002, d, Y, , , 1
002, e, N, , , 1
run; * target eye 1=left, 2=right;
Notes:
- There are 2 subjects here and 5 visits.
- The first visit (A) is screening, and the data doesn't show up there GLAUCOMA. But does appear for GLAUCOMA_R GLAUCOMA_L. This is bc data was capture at screening for both eyes.
- Every subsequent visit, data was only collected for the target eye.So that is why values populate for GLAUCOMA for visit B (dosing) and onwards, but not for the other two columns for GLAUCOMA_R and GLAUCOMA_L.
- TARGET_EYE is coded so that the 1=left and 2=right. So for the first subject, i want for that person's row for Visit A to be value for GLAUCOMA_R, since their target_eye value is 2.
This is what the desired output should look like:
Note that for Visit A rows, 2 cells that were missing in GLAUCOMA now are filled when before they were empty. Also note, although not relevant, that the two subjects had their issues resolved by the fifth and final visit (visit e).
Thanks
What would target_eye be if both glaucoma_r and glaucoma_l were both Y or both N?
Try this. It gives the same answer you've provided. If both glaucoma variables are N or Y then I set target_eye2 to missing for now.
proc sort data = have1;
by usubjid visit;
run;
data want;
set have1;
by usubjid;
retain target_eye2;
if first.usubjid and visit = 'a' then do;
if glaucoma_l = 'Y' and glaucoma_r = 'N' then target_eye2 = 1;
else if glaucoma_l = 'N' and glaucoma_r = 'Y' then target_eye2 = 2;
else target_eye2 = .;
end;
run;
Hey, thanks for the response!
I found another way that i think does the trick. Here you go, in case you are interested.
data visit_a; set have1;
if visit eq "a";
if target_eye=1 then glaucoma=glaucoma_l; else glaucoma=glaucoma_r;
run;
data other_visits; set have1;
if visit ne "a";
run;
data want; set visit_a other_visits;
run;
proc sort; by usubjid visit; run;
Thanks for answering!
Looks like I misinterpreted your question. You wanted to derive the glaucoma variable from target_eye and not the other way around. As long as you got the answer you wanted...
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: