Hello everybody,
I am doing an event study with trading data using SAS Studio and I need to delete any stocks from my data set which have not been traded, i.e. their closing prices do not change over time. I have a sample of stocks with about 150 trading day records. My (for this task relevant) variables are date, firm and price. So what I want to do is to delete any firms which have not been traded for 3 days in a row or more. I attached one of my data sets. Does anybody know how to do this?
Thanks!
Use by group processing and the lag functions within a data step to determine firms to delete, then merge:
data del (keep=firm);
set sascomm.aerospacedefense;
by firm;
retain flag;
plag1 = lag(price);
plag2 = lag2(price);
if first.firm then flag = 0;
if lag(firm) = lag2(firm) = firm and plag1 = plag2 = price then flag = 1;
if last.firm and flag then output;
run;
data want;
merge
sascomm.aerospacedefense
del (in=d)
;
by firm;
if not d;
run;
Do you have a target date, eg "has not been traded in the last three days immediately before ...", or does any sequence of three days without a change qualify for deletion?
My estimation window is from April 1 to November 8, so any series of three days or more of no trading before November 8, 2016 qualifies for deletion.
Use by group processing and the lag functions within a data step to determine firms to delete, then merge:
data del (keep=firm);
set sascomm.aerospacedefense;
by firm;
retain flag;
plag1 = lag(price);
plag2 = lag2(price);
if first.firm then flag = 0;
if lag(firm) = lag2(firm) = firm and plag1 = plag2 = price then flag = 1;
if last.firm and flag then output;
run;
data want;
merge
sascomm.aerospacedefense
del (in=d)
;
by firm;
if not d;
run;
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.