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

Good evening,

 

I'm working with a panel data set consisting of firm-year observations. This data set includes a dummy variable called "acquisition" that equals 1 if the firm made an acquisition during the current year and 0 otherwise. Now, I'd like to construct a new dummy variable that captures prior acquisition experience. More specifically, I'd like for this new variable to equal 1 if the acquisition dummy for this firm equals 1 in any prior year and 0 otherwise. Unfortunately, I'm having trouble figuring out the appropriate code. I thought it would be easiest to first create a count variable that reveals the number of prior years with merger activity and then construct a dummy variable equal to 1 any time the count variable carries a non-zero value. However, I can't seem to get the count variable to work. 

 

 

Does anyone have any advice?  For simplicity, you can just assume that the data set consists of 3 variables: id, year, and acquisition (a dummy variable).

 

Thank you!

 

Aimee      

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

One way (assuming your data set is sorted by FIRM YEAR):

 

data want;

set have;

by firm;

retain prior_acquisition;

if first.firm then prior_acquisition = 0;

output;

prior_acquisition = max(prior_acquisition, acquisition);

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

One way (assuming your data set is sorted by FIRM YEAR):

 

data want;

set have;

by firm;

retain prior_acquisition;

if first.firm then prior_acquisition = 0;

output;

prior_acquisition = max(prior_acquisition, acquisition);

run;

aimsmith12
Calcite | Level 5
Thank you so much for your help! I really appreciate it. The code you suggested does exactly what I was trying to do.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1040 views
  • 0 likes
  • 2 in conversation