Identify New Appearances: If a company's "RIC" is in this quarter but wasn't in the previous quarter, I want to mark it as 1; otherwise, it's 0. This helps me know when a company appears for the first time or reappears after some time. Spot Disappearances: If a company's "RIC" is here in this quarter but disappears in the next quarter, I also want to mark it as 1; otherwise, it's 0. This helps me know when a company goes away. Handling Comebacks After a Gap: If a company's "RIC" is there in one quarter, then it disappears for a couple of quarters, and then comes back, I want SAS to treat it as a "new" appearance. So, it should get a 1 to show that it's starting fresh. I tried following code but its not working. It would be helpful, if you can help.
data data1;
set data1;
informat RIC $6.;
informat QuarterYear $6.;
by RIC QuarterYear;
retain last_quarter last_ric existed_in_current_quarter first_ric;
if last_quarter ne . and (QuarterYear ne intnx('quarter', last_quarter, 1) or missing(QuarterYear)) then do;
first_ric = .;
end;
if last_ric ne . and last_ric = RIC then existed_in_current_quarter = 0;
else existed_in_current_quarter = 1;
if first_ric = . and existed_in_current_quarter = 1 then first_ric = RIC;
output;
last_quarter = QuarterYear;
last_ric = RIC;
run;
... View more