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
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
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
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.
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
Works like a charm! Thank you!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.