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

Hi all, 

I have the following dataset and I am trying to create a dummy variable that takes one for execid that held a CEO position at another firm and zero otherwise. Thank you! 

data have;
input execid companyid role $ date yymmdd8.;
format date date9.;
cards;
1 21 Chairman 20191128
1 21 CEO 20170214
1 13 CEO 20160530
1 13 CFO 20140622
1 18 Director 20110831
1 18 Director 20091220
1 18 CEO 20070217
1 18 CEO 20060302
1 42 CFO 20050410
1 42 Advisor 20040425
1 36 CFO 20020609
1 36 Member 20021025
1 36 Member 20000612
2 31 Advisor 20190515
2 31 Advisor 20160813
2 29 Chairman 20120522
2 28 Director 20110524
2 28 CEO 20090919
2 26 CFO 20080101
2 26 CFO 20060321
;run;

 

Here is my desired dataset.

 

execidcompanyidroledateCEO_Dummy
121Chairman201911281
121CEO201702141
113CEO201605301
113CFO201406221
118Director201108310
118Director200912200
118CEO200702170
118CEO200603020
142CFO200504100
142Advisor200404250
136CFO200206090
136Member200210250
136Member200006120
231Advisor201905151
231Advisor201608131
229Chairman201205221
228Director201105241
228CEO200909191
226CFO200801011
226CFO200703211
231Advisor200608131
229Chairman200505221
228Director200405241
228CEO200309190
226CFO200301010
226CFO200103210

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Why in your desired result does the earliest entry for execid=2 start with a CEO_Dummy=1?

Patrick_0-1630802142906.png

Should the ceo_dummy become 1 if the role has been 'CEO' in any of the previous companies or only if it was the most recent previous one?

 

Below above two options implemented - but none matches your desired result. Can you please specify the required logic further.

data have;
  input execid companyid role $ date yymmdd8. expected_ceo_flg :$1.;
  format date date9.;
cards;
1 21 Chairman 20191128 1
1 21 CEO 20170214 1
1 13 CEO 20160530 1
1 13 CFO 20140622 1
1 18 Director 20110831 0
1 18 Director 20091220 0
1 18 CEO 20070217 0
1 18 CEO 20060302 0
1 42 CFO 20050410 0
1 42 Advisor 20040425 0
1 36 CFO 20020609 0
1 36 Member 20021025 0
1 36 Member 20000612 0
2 31 Advisor 20190515 1
2 31 Advisor 20160813 1
2 29 Chairman 20120522 1
2 28 Director 20110524 1
2 28 CEO 20090919 1
2 26 CFO 20080101 1
2 26 CFO 20060321 1
2 31 Advisor 20160813 1
2 29 Chairman 20120522 1
2 28 Director 20110524 1
2 28 CEO 20090919 0
2 26 CFO 20080101 0
2 26 CFO 20060321 0
;

proc sort data=have;
  by execid date;
run;

data want(drop=_:);
  set have;
  by execid companyid notsorted;
  length _ceo_any _ceo_last $1;
  retain _ceo_any _ceo_last;

  length ceo_any_flg ceo_last_flg $1;
  retain ceo_any_flg ceo_last_flg;


  if first.execid then
    do;
      _ceo_any='0';
      _ceo_last='0';
      ceo_any_flg=_ceo_any;
      ceo_last_flg=_ceo_last;
    end;

  if not first.execid and first.companyid then
    do;
      ceo_any_flg=_ceo_any;
      ceo_last_flg=_ceo_last;
      _ceo_last='0';
    end;

  if role='CEO' then
    do;
      _ceo_any='1';
      _ceo_last='1';
    end;
run;

Patrick_0-1630803712595.png

 

View solution in original post

6 REPLIES 6
japelin
Rhodochrosite | Level 12

How about this code.

data want;
  set have;
  ceo_dummy=mod(floor(rand('UNIFORM', 1, 100)),2);
run;
AmirSari
Quartz | Level 8
Thank you for your reply. This does not produce what I am looking for. I want an indicator variable that is one if the executive, i.e. execid, held a CEO position in his/her prior experience and zero otherwise.
Patrick
Opal | Level 21

Why in your desired result does the earliest entry for execid=2 start with a CEO_Dummy=1?

Patrick_0-1630802142906.png

Should the ceo_dummy become 1 if the role has been 'CEO' in any of the previous companies or only if it was the most recent previous one?

 

Below above two options implemented - but none matches your desired result. Can you please specify the required logic further.

data have;
  input execid companyid role $ date yymmdd8. expected_ceo_flg :$1.;
  format date date9.;
cards;
1 21 Chairman 20191128 1
1 21 CEO 20170214 1
1 13 CEO 20160530 1
1 13 CFO 20140622 1
1 18 Director 20110831 0
1 18 Director 20091220 0
1 18 CEO 20070217 0
1 18 CEO 20060302 0
1 42 CFO 20050410 0
1 42 Advisor 20040425 0
1 36 CFO 20020609 0
1 36 Member 20021025 0
1 36 Member 20000612 0
2 31 Advisor 20190515 1
2 31 Advisor 20160813 1
2 29 Chairman 20120522 1
2 28 Director 20110524 1
2 28 CEO 20090919 1
2 26 CFO 20080101 1
2 26 CFO 20060321 1
2 31 Advisor 20160813 1
2 29 Chairman 20120522 1
2 28 Director 20110524 1
2 28 CEO 20090919 0
2 26 CFO 20080101 0
2 26 CFO 20060321 0
;

proc sort data=have;
  by execid date;
run;

data want(drop=_:);
  set have;
  by execid companyid notsorted;
  length _ceo_any _ceo_last $1;
  retain _ceo_any _ceo_last;

  length ceo_any_flg ceo_last_flg $1;
  retain ceo_any_flg ceo_last_flg;


  if first.execid then
    do;
      _ceo_any='0';
      _ceo_last='0';
      ceo_any_flg=_ceo_any;
      ceo_last_flg=_ceo_last;
    end;

  if not first.execid and first.companyid then
    do;
      ceo_any_flg=_ceo_any;
      ceo_last_flg=_ceo_last;
      _ceo_last='0';
    end;

  if role='CEO' then
    do;
      _ceo_any='1';
      _ceo_last='1';
    end;
run;

Patrick_0-1630803712595.png

 

AmirSari
Quartz | Level 8
The earliest entry for execid=2 starts with a CEO_Dummy=1 because this executive held a CEO role in companyid=28 in 2009. I want the dummy to become 1 if the role has been 'CEO' in any of the previous companies.
Patrick
Opal | Level 21

@AmirSari wrote:
The earliest entry for execid=2 starts with a CEO_Dummy=1 because this executive held a CEO role in companyid=28 in 2009. I want the dummy to become 1 if the role has been 'CEO' in any of the previous companies.

The role held in companyid=28 was AFTER the role held in companyid=26 so that's not PREVIOUS company.

Patrick_0-1630805483225.png

 

AmirSari
Quartz | Level 8
You are absolutely right! I messed up the dates. My bad, sorry1 I corrected my post.
Thank you for your solution. It works the way I wanted.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 6 replies
  • 1451 views
  • 0 likes
  • 3 in conversation