As you no longer require duplication of values to replace missing values the process can be simplified. Key features: create an invalue seq for an input function rather than using put with automatic type conversion Create a restricted Cartesian product of subjid and day (normally a bad idea!) to form a template of all possible subjid and day combinations Use a left join to update the template with value from new Use the sum function, with zero, to convert missing values to zero NOTE: This code generates values for subjid = 4 and day = week2 and week4, which are not in your want table. If you use this code you may need a datastep to delete these values based on whether the last undeleted row was a baseline, if I understand your data correctly. I can add that if you require. proc format; invalue seq 'baseline'=1 'week2'=2 'week4'=3 'week8'=4 'week12'=5 ; quit ; data new; length subjid $8 day $10 value 8; input subjid day value; datalines; 1 baseline 10 1 week2 12 1 week4 14 1 week8 16 1 week12 12 2 baseline 10 2 week2 12 2 week4 10 3 baseline 10 3 week2 3 3 week8 4 4 baseline 10 4 week8 4 ; Proc SQL ; Create Table template As Select distinct a.subjid , b.day , input (b.day, seq.) as seq From new a , new b Order By a.subjid , seq ; Create Table want (drop = seq) As Select tmp.* , Sum (new.value, 0) As value From template tmp Left Join new new On new.subjid = tmp.subjid And new.day = tmp.day Order By tmp.subjid , tmp.seq ; Select * from want ; Quit ; subjid day value ------ --- ----- 1 baseline 10 1 week2 12 1 week4 14 1 week8 16 1 week12 12 2 baseline 10 2 week2 12 2 week4 10 2 week8 0 2 week12 0 3 baseline 10 3 week2 3 3 week4 0 3 week8 4 3 week12 0 4 baseline 10 4 week2 0 4 week4 0 4 week8 4 4 week12 0 Regards Richard in Oz
... View more