Let's generalize a little, and assume that TEMP2 has more than one observation, and has more than one variable, some of which may not be in TEMP1.
data temp1;
input Visit :$4. tpt VAL;
datalines;
C1D1 -12 1
C2D1 0 2
C3D1 1 4
C4D1 2 5
C5D1 3 1
run;
data temp2;
input val newvar;
datalines;
3 1001
3.1 1002
run;
Then it might be worthwhile to make a hash of TEMP2 (with an additional _ORDER variable). For each obs in TEMP1, output to temp3 and add an extra obs for every dataitem in the hash, in sequence determined by _ORDER.
data dummy2;
_order=_n_;
set temp2;
run;
data temp3 (drop=_:) ;
set temp1;
output;
if _n_=1 then do;
if 0 then set dummy2 nobs=size_of_temp2;
declare hash h (dataset:'dummy2');
h.definekey('_order');
h.definedata(all:'Y');
h.definedone();
end;
do _order=1 to size_of_temp2;
h.find(key:_order);
output;
end;
call missing(of _all_);
run;
... View more