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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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?

Annalena
Fluorite | Level 6

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.

Kurt_Bremser
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

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.

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
  • 3 replies
  • 914 views
  • 1 like
  • 2 in conversation