Hello Andreas, Thank you for your reply the other day. When I am trying to run the program on a larger dataset, unfortunately the results are not coming as expected. For instance, the result for GVKEY 001209, GVKEY 004321. Would be grateful if you could kindly give me any suggestions as to how I can fix this issue. I am attaching the larger dataset here. Since I have modified the names of the columns a bit, I am copying your same code with the names a bit modified here for your convenience. proc sort data=work.have out= sorted1; where Datadate < '13Apr2009'd and FQTR in (2, 4); by GVKEY descending Datadate; run; data work.result1; set work.sorted1; by GVKEY descending Datadate; retain output_next 0; if FQTR = 4 then output_next = 1; if FQTR = 2 and output_next = 1 then do; output; output_next = 0; end; drop output_next; run; proc sort data=work.result1 out=work.want1; by descending GVKEY Datadate; run;
... View more