Fluorite | Level 6

## data manipulation

data temp1;
input teacher \$ class \$ score;
cards;
A C1 70
A C2 80
B C3 90
B C4 99
C C5 76
D C6 95
;
run;

data temp2;
input teacher \$ class \$ weight ;
cards;
A C2 0.5
B C2 0.5
B C3 0.333
C C3 0.333
D C3 0.333
;
run;

from temp1,Class C1, C4, C5 and C6 are taught independently by teacher A , B, C and respectively.

from temp2, Class C2 is co-taught by teacher A and B (weight 0.5 each), but data temp1 only has A's data not B's.

Class C3 is co-taught by teacher B, C, and D (weight 0.3333 each), again but data temp1 only has B's data not C D.

I wan to create a new data set to copy the co-teach (class and score) information as follows: variables are teacher class score and weight(only co-taught courses have weights)

A C1 70 .
A C2 80 0.5
B C2 80 0.5
B C3 90 0.333
C C3 90 0.333
D C3 90 0.333
B C4 99 .
C C5 76 .
D C6 95 .

2 REPLIES 2
Tourmaline | Level 20

## Re: data manipulation

Try this

``````data want(drop=s);
merge temp1 temp2;
by class teacher;
if score then s = score;
retain s;
if score = . then score = s;
run;``````

Result

```teacher class score weight
A       C1    70    .
A       C2    80    0.500
B       C2    80    0.500
B       C3    90    0.333
C       C3    90    0.333
D       C3    90    0.333
B       C4    99    .
C       C5    76    .
D       C6    95    .
```
Tourmaline | Level 20

## Re: data manipulation

Simpler:

``````data want;
merge temp1 temp2;
by class teacher;
if score then _iorc_ = score;
else score = _iorc_;
run;``````
Discussion stats
• 2 replies
• 421 views
• 1 like
• 2 in conversation