Keep the last non-missing value for each variable
I think there is an error in you 'want' table
TDR(AGE)=70 not 80
HAVE
====
Up to 40 obs WORK.HAVE total obs=4
Obs NAME AGE NET REG LOSS
1 home 300 200 50 .
2 home 100 80 . 5
3 TDR 80 75 . 3
4 TDR 70 . 5 .
WANT
====
Obs NAME AGE NET REG LOSS
1 home 100 80 50 5
2 TDR 70 75 5 3
SOLUTION
* I set this up to work with an arbitrary number of numeric columns;
* Do not need disubl if you hardcode variable names;
* I wish SAS would make the number of coluns available at compilation time;
data have;
input Name $ Age Net Reg Loss;
cards4;
home 300 200 50 .
home 100 80 . 5
TDR 80 75 . 3
TDR 70 . 5 .
;;;;
run;quit;
data _null_;
set have(obs=1);
array nums _numeric_;
call symputx('nums',put(dim(nums),5.));
rc=dosubl('
data want;
set have;
by name notsorted;
array nums _numeric_;
array savs[&nums.] _temporary_;
do i=1 to dim(nums);
if nums[i] ne . then savs[i]=nums[i];
end;
do i=1 to dim(nums);
nums[i]=savs[i];
end;
if last.name then output;
run;quit;
');
run;quit;
... View more