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

Hello,

 

I need create dummy variable that indicates whether the firm's market value increases in a given year.

 

This is to test whether executives are rewarded when the firm does well, but to be relatively insulated from downturns in firm performance. 

 

I was getting started on my datastep:

 

data paper.ceo_firm;
	Set paper.ceo_firm;
	if annual_return<=0 then increase=0;
	else if annual_return>0 then increase=1;
run;

However, I realized that this would only show whether the growth was positive or negative--nothing to do with growth from the previous year. Do you have any suggestions? Here is an example of what the data look like:

 

Row

Ticker yearannual_return                         
2A 201133.914554388William P. Sullivan 1000 18297AGILENT TECHNOLOGIES INCChief Executive Officer, President, Executive Director and Member of Executive CommitteeCEO99003521.5053788.3021922.258030.19910252.2649906730.75924844.5084325.05128199.283902.3790.259
3A 201233.914554388William P. Sullivan 1000 18297AGILENT TECHNOLOGIES INCChief Executive Officer, Executive Director and Member of Executive CommitteeCEO99003859.1834007.7911247.808030.93510135.7179906276.5345032.3034963.28424120.4831003.0520.303
4A 201333.914554388William P. Sullivan 1000 18297AGILENT TECHNOLOGIES INCChief Executive Officer, President, Executive Director and Member of Executive CommitteeCEO104503789.9364141.21228.875030.66110235.672104510235.67210577.114841.16737106.1571200.7290.362
5A 201433.914554388William P. Sullivan 1000 18297AGILENT TECHNOLOGIES INCChief Executive Officer, Executive Director and Member of Executive CommitteeCEO105006632.834569.0331631.089031.78113914.733105013914.73322578.8255377.64637931.67960.6610.29
6A 201533.914554388Michael R. McMullen 1000 39774AGILENT TECHNOLOGIES INCChief Executive Officer, President, Director and Member of Executive CommitteeCEO845.83302520.2052434.5241110.96370.994225.3337207.852845.8337207.8524661.91512891.19912891.199564.5090.172
7A 201633.914554388Michael R. McMullen 1000 39774AGILENT TECHNOLOGIES INCChief Executive Officer, President and DirectorCEO1041.66706341.25501338.18348.144145.1668914.4151041.6678914.4157169.50620377.07820377.078571.3210.177
8AABA 201015.7205Carol A. Bartz, Ph.D. 1000 42606ALTABA INCChief Executive Officer, President and DirectorCEO100006626.9952114.474220005.36511946.834100011946.8343822.85910429.98924283.055722.3810.06
9AABA 201115.7205Carol A. Bartz, Ph.D. 1000 42606ALTABA INCChief Executive Officer, President and DirectorCEO735.02509414.2112601.376477.53403141.38916369.535735.02516369.53510843.741001351.9840.123
10AABA 201215.7205Marissa A. Mayer 1000147607ALTABA INCChief Executive Officer, President and DirectorCEO454.862035000.00201120040.5436615.404454.86236615.4045886.29615453.9747409.022201.2980.018
11AABA 201315.7205Marissa A. Mayer 1000 47607ALTABA INCChief Executive Officer, President and DirectorCEO10002.258312.31613847.2831700073.86324935.7121002.2524935.71124027.97440222.367164642.746625.7170.062
12AABA 201415.7205Marissa A. Mayer 1000 47607ALTABA INCChief Executive Officer, President and DirectorCEO1000011752.35528194.2881108.8028.06542083.508100042083.50848053.66436078.517157910.0561009.3360.108
13AABA 201515.7205Marissa A. Mayer 1000 47607ALTABA INCChief Executive Officer, President and DirectorCEO10001.12514495.49419935.77700548.71135981.1071001.12535981.10737453.6039087.41454888.5811340.0470.142
14AABA 201615.7205Marissa A. Mayer 1000 47607ALTABA INCChief Executive Officer, President and DirectorCEO1000011328.98813329.961001751.2127410.159100027410.15816959.72327566.55742701.6431599.2680.167
15AAI 201035.556214472Robert L. Fornaro 1000 36038AIRTRAN HOLDINGS INCChairman, Chief Executive Officer, President, Chairman of Financial Policy & Risk Committee, Chairman of AirTran Airways, Chief Executive Officer of AirTran Airways and President of AirTran AirwaysCEO564870606.57000122.8342163.40414342163.4042579.5792249.5595671.197545.4690.398
16AAL 201097.934339046Gerard J. Arpey

 

 

 

 

 

 

 

Let me know if you need any more details. Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use the lag() function to access previous values, and by-group processing:

data paper.ceo_firm;
set paper.ceo_firm;
by company year;
last_return = lag(annual_return);
if not first.company
then increase = (annual_return >  last_return);
else increase = .;
run;

The condition (annual_return > last_return) will return 1 for true or 0 for false.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

Use the lag() function to access previous values, and by-group processing:

data paper.ceo_firm;
set paper.ceo_firm;
by company year;
last_return = lag(annual_return);
if not first.company
then increase = (annual_return >  last_return);
else increase = .;
run;

The condition (annual_return > last_return) will return 1 for true or 0 for false.

sastuck
Pyrite | Level 9

Thank you for the suggestion--this looks to be exactly what I need!

 

However, upon running the code, I ran into an error message:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 data paper.ceo_firm;
72 set paper.ceo_firm;
73 by company year;
74 last_return = lag(annual_return);
75 if not first.company
76 then increase = (annual_return > last_return);
77 else increase = .;
78 run;
 
ERROR: BY variable company is not on input data set PAPER.CEO_FIRM.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set PAPER.CEO_FIRM may be incomplete. When this step was stopped there were 0 observations and 111 variables.
WARNING: Data set PAPER.CEO_FIRM was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 2315.59k
OS Memory 29100.00k
Timestamp 04/02/2018 12:38:26 PM
Step Count 23 Switch Count 0
Page Faults 0
Page Reclaims 681
Page Swaps 0
Voluntary Context Switches 31
Involuntary Context Switches 0
Block Input Operations 288
Block Output Operations 8
 
 
79
80 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
92
 
 
"company" isn't actually a variable in the data set. "conname" might be what you're looking for here? 
art297
Opal | Level 21

Isn't TICKER the variable for which you want to identify whether there were increases? i.e.:

data paper.ceo_firm;
set paper.ceo_firm;
by ticker year;
last_return = lag(annual_return);
if not first.ticker
then increase = (annual_return >  last_return);
else increase = .;
run;

Art, CEO, AnalystFinder.com

 

sastuck
Pyrite | Level 9

Thank you. This is just what I was looking for. 

Kurt_Bremser
Super User

Since you did not post example data in a usable form (data step with datelines), I had to write the code on-the-fly. Adapt it to your data structure as needed.


@sastuck wrote:

Thank you for the suggestion--this looks to be exactly what I need!

 

However, upon running the code, I ran into an error message:

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 data paper.ceo_firm;
72 set paper.ceo_firm;
73 by company year;
74 last_return = lag(annual_return);
75 if not first.company
76 then increase = (annual_return > last_return);
77 else increase = .;
78 run;
 
ERROR: BY variable company is not on input data set PAPER.CEO_FIRM.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set PAPER.CEO_FIRM may be incomplete. When this step was stopped there were 0 observations and 111 variables.
WARNING: Data set PAPER.CEO_FIRM was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 2315.59k
OS Memory 29100.00k
Timestamp 04/02/2018 12:38:26 PM
Step Count 23 Switch Count 0
Page Faults 0
Page Reclaims 681
Page Swaps 0
Voluntary Context Switches 31
Involuntary Context Switches 0
Block Input Operations 288
Block Output Operations 8
 
 
79
80 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
92
 
 
"company" isn't actually a variable in the data set. "conname" might be what you're looking for here? 

 

sastuck
Pyrite | Level 9

Could you explain or show an example of what data step with datelines this would look like? Just for future reference. Do you just mean showing the log after running the relevant datastep? Just wondering. 

 

Thanks!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 7 replies
  • 1340 views
  • 2 likes
  • 3 in conversation