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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.