/* Vision test results on patients with macular degeneration */ /* Vision was tested at the outset of the study, after 3 months, */ /* after 12 months, and after 24 months. The second number is the */ /* important number in Snellen */ data a; input Patient $ Group $ Gender $ Age Snellen0 $7. +1 Snellen3 $7. +1 Snellen12 $7. +1 Snellen24 $7. ; datalines; A1340 Trt M 64 6 by 60 6 by 60 2 by 60 3 by 60 B1456 Con F 57 6 by 36 6 by 36 6 by 60 6 by 60 A1332 Con F 72 6 by 36 6 by 30 6 by 18 6 by 18 C1345 Trt M 70 6 by 18 6 by 36 6 by 36 6 by 60 A0457 Con M 71 3 by 36 3 by 24 6 by 60 6 by 36 ; proc print data=a; run; /* A transpose that doesn't save all the variables */ proc sort data=a; by patient; proc transpose data=a out=out1; by patient; var Snellen0 Snellen3 Snellen12 Snellen24; proc print data=out1; run; /* A transpose that saves all the other demographics */ proc sort; by patient group gender age; proc transpose data=a out=out2; by patient group gender age; var Snellen0 Snellen3 Snellen12 Snellen24; proc print data=out2; run; /* Let's change a couple column names */ proc transpose data=a out=out3(rename=(col1=Csnellen)) name=Cmonth; by patient group gender age; var Snellen0 Snellen3 Snellen12 Snellen24; proc print data=out3; run; /* And fix up Month and Snellen so they can be */ /* treated as either factors or covariates */ data out4; set out3; Snellen=input(substr(Csnellen,6,2),2.); Month=input(substr(Cmonth,8,2),2.); proc print; run; /* The actual data set included several more variables */ /* measured over time--these were transposed separately */ /* by ID only, sorted by ID and Month and then combined */ /* using a merge by ID and Month */ /* /* We can transform the data back to its original form; */ /* this should help you understand the use of the ID statment. */ /* Since we didn't specifically save the first part of the */ /* acuity character data, we won't completely re-create the */ /* original format of the data. */ proc sort data=out4; by patient group gender age; proc transpose data=out4 out=out5; by patient group gender age; var snellen; id month; run; proc print data=out5; run; /* Here's a little more clean-up */ proc sort data=out4; by patient group gender age; proc transpose data=out4 out=out6 (drop=_name_) prefix=Snellen; by patient group gender age; var snellen; id month; run; proc print data=out6; run;