BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tish
Calcite | Level 5

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;

art297
Opal | Level 21

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;


ncross
Calcite | Level 5

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?

art297
Opal | Level 21

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.

bream_bn
Fluorite | Level 6

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 19 replies
  • 2455 views
  • 6 likes
  • 6 in conversation