Separating pretest scores from posttest scores

Chong Ho Yu, Ph.D.



There is a data file carrying both pretest and posttest scores in the same field. However, no column is used to indicate which entry is from the pretest and which one is from the posttest. What I know is that when there are two rows belonging to the same ID, the first row is the pretest datum. I would like to separate the pretest scores from the posttest scores. What can I do?

Pretest and posttest scores

ID scores
12345 80
12345 100
45678 85
45678 90
99999 98
99999 100


Pretest and posttest
scores Rank

ID scores rank
12345 80 1
12345 100 2
45678 85 3
45678 90 4
99999 98 5
99999 100 6

The following SAS code is not the most efficient one, but it works. The logic is as follows: Every subject has two entries and the first one in each pair is the pretest. In this case, the rank order number of each pretest record is always an odd number: 1, 3, 5, 7, 9. By the same token, that of each posttest record is always an even number: 2, 4, 6, 8, 10. The following code utilize this pattern for separation. Please read the comments (text in green) for the step-by-step illustration.




SAS program for separating pretest and posttest scores

/* assume that the data file has been imported and is named 'one' */

data two; set one;

/* set the order of the observation as the temporary ID and concatenate

it with the character "S" */

temp = _N_ || "S" ;

/* search for any observation that ends with an odd number. The letter "S" forces

SAS to look at the end only */

if index (temp, "1S") then flag = 1;

if index (temp, "3S") then flag = 1;

if index (temp, "5S") then flag = 1;

if index (temp, "7S") then flag = 1;

if index (temp, "9S") then flag = 1;

/* separate pretest scores from posttest scores by flag */

if flag = 1 then test = "pretest ";

else if flag = . then test = "posttest";




SAS tips contents

Computer write-ups contents

Simplified Navigation

Table of Contents

Search Engine