Below is a simple example of a more complex task I am trying to accomplish. What I want to do is read through all the data and accumulate AMT grouped by product using a hash object and output the hash object as a dataset once the end of the input is reached. I want to only include products A and B and need to do this with a subsetting IF statement. The two input datasets, HAVE1 and HAVE2 are identical except for the order of the records. I get the output I want when I use HAVE1 but not with HAVE2 and I think it is because the last record in HAVE2 doesn't satisfy the subsetting IF statement. I am sure there is a simple solution, I am just not seeing it. Any insight is appreciated. Thanks in advance. data work.HAVE1;
input PRODUCT $ AMT;
datalines;
A 100
A 200
B 500
C 1000
B 800
;
run;
data work.HAVE2;
input PRODUCT $ AMT;
datalines;
A 100
A 200
B 500
B 800
C 1000
;
run;
data _null_;
if _n_ = 1 then do;
declare hash tot();
tot.definekey ("PRODUCT");
tot.definedata ("PRODUCT", "TOTAL");
tot.definedone();
end;
do until (EOF);
set work.HAVE1 end= EOF;
if PRODUCT in ("A","B");
if tot.find() ne 0 then call MISSING(TOTAL);
TOTAL + AMT;
tot.replace();
end;
tot.output(dataset: "work.WANT");
run;
... View more