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

Hi,


I would like to retain a certain observation in SAS for a certain amount of observations forward.


If a criteria is met (date=announcement_date) then retain the value for the next 60 observations.

I don't want to write 60 lags but also make it flexible and change the 60 to 30 or whatever.

 

Best,
M

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I set the iterations to 6 in the following example, but that could be changed to 30, 60 or whatever you want:

data want (drop=counter);
  set have;
  retain dummy;
  if missing(counter) then do;
    if date eq announcement_date then do;
      dummy=x;
      counter=0;
    end;
  end;
  else do;
    counter+1;
    if date eq announcement_date then do;
      dummy=x;
      counter=0;
    end;
    if counter eq 6 then do;
      call missing(counter);
      call missing(dummy);
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

After you've initially found a record that met your criterion and are retaining it for the next 60 observations, do you need to continue to check that criterion on the subsequent records? In short, tell us more about what you are trying to accomplish.

 

Art, CEO, AnalystFinder.com

 

MarcBoh
Obsidian | Level 7

Thanks for the reply.

 

I want to establish an event study and one data set as stocks, dates and prices. the second one has stocks and announcement dates.

So basically always when date=announcement_date I want to fill in an additional (dummy variable) with just ones into the next 60 rows.

 

 

art297
Opal | Level 21

I set the iterations to 6 in the following example, but that could be changed to 30, 60 or whatever you want:

data want (drop=counter);
  set have;
  retain dummy;
  if missing(counter) then do;
    if date eq announcement_date then do;
      dummy=x;
      counter=0;
    end;
  end;
  else do;
    counter+1;
    if date eq announcement_date then do;
      dummy=x;
      counter=0;
    end;
    if counter eq 6 then do;
      call missing(counter);
      call missing(dummy);
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

MarcBoh
Obsidian | Level 7

Works like a charm! Thank you!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 956 views
  • 0 likes
  • 2 in conversation