BookmarkSubscribeRSS Feed
Hello_there
Lapis Lazuli | Level 10
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:

Hello_there_0-1651786678938.png

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

5 REPLIES 5
SASKiwi
PROC Star

What would target_eye be if both glaucoma_r and glaucoma_l were both Y or both N?

Hello_there
Lapis Lazuli | Level 10
Good question. It would just be whatever eye the experimenter wants to test, either left or right.
SASKiwi
PROC Star

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;

 

 

Hello_there
Lapis Lazuli | Level 10

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!

SASKiwi
PROC Star

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...

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 385 views
  • 2 likes
  • 2 in conversation