Okay, how about the following? You can drop index_year and test_yearmonth as you see fit.
data desired discarded;
set raw;
by permno;
retain index_year;
test_yearmonth = input(yearmonth, yymmn6.);
if first.permno or
intck("year", index_year, test_yearmonth) > 2 then
do;
index_year = year(test_yearmonth);
output desired;
end;
else
output discarded;
run;
I still probably don't understand what you are trying to do and your examples don't seem to match the example dataset that you provided.
Like Tish, I changed my code to use the actual date, but didn't keep the calculated SAS date,
data want1 leftover;
set have;
if distcd IN (1262,1272) then output leftover;
else output want1;
run;
data want2 deleted;
set leftover;
by permno;
last_DCLRDT=lag(DCLRDT);
if first.permno then output want2;
else do;
if intck('year',input(put(last_DCLRDT,8.),yymmdd8.),input(put(DCLRDT,8.),yymmdd8.),'c')
le 2 then output deleted;
else output want2;
end;
drop last_:;
run;
data want;
set want1 want2;
run;
proc delete data=want1;
run;
proc delete data=want2;
run;
proc delete data=leftover;
run;
proc sort data=want;
by permno year;
run;
Hi Tish and Arthur I try tweaking the codes to 3 year or 5 year hiatus and I am receiving the same output. Where I see the "2" i replace the digit is there something I am doing wrong?
I'd suggest starting a new thread, including a small example dataset, and explain what you are trying to do and the result (given the example) that you want to achieve.
I came up with the below
data finaldata;
set testdata;
by permno distcd yearmonth ;
retain last_yearmo;
proc sort data=testdata;
by permno distcd yearmonth ;
run;
if not first.permno or not first.distcd then do;
val = yearmonth - last_yearmo;
if val <= 200 then delete;
end;
last_yearmo=yearmonth;
run;
This though would delete 196600 from (196400 196600 196800) and not 196800
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.