BookmarkSubscribeRSS Feed
tinghlin
Fluorite | Level 6

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
PeterClemmensen
Tourmaline | Level 20

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    . 
PeterClemmensen
Tourmaline | Level 20

Simpler:

 

data want;
   merge temp1 temp2;
   by class teacher;
   if score then _iorc_ = score;
   else score = _iorc_;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 488 views
  • 1 like
  • 2 in conversation