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

Hi All,

I need your help. I am trying to create a variable "Change" that takes value 1 for years after the CEO change. The information I have includes TIC (firm identifier), YEAR, and CEO. For instance,

TIC YEAR CEO

A     2005     Frank

A     2006     Frank

A     2007     TOD

A     2008     TOD

A     2009     TOD

The output I am trying to get is:

TIC YEAR CEO     CHANGE

A     2005     Frank     0

A     2006     Frank     0

A     2007     TOD     1

A     2008     TOD     1

A     2009     TOD     1

I would appreciate if someone share with me the right code.

Thank you

SS

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

A DO UNTIL loop will do the trick:

data have;

input TIC $ YEAR CEO$;

datalines;

A     2005     Frank

A     2006     Frank

A     2007     TOD

A     2008     TOD

A     2009     TOD

;

data want;

nCEO = 0;

do until (last.TIC);

  set have; by TIC CEO notsorted;

  nCEO + first.CEO;

  CHANGE = nCEO > 1;

  output;

  end;

drop nCEO;

run;

 

proc print data=want noobs; run;

PG

PG

View solution in original post

3 REPLIES 3
RichardinOz
Quartz | Level 8

You state "variable "Change" that takes value 1 for years after the CEO change" but in your example the variable persists for the next 2 years.  Please confirm which is your requirement.

Richard.

shalmali
Calcite | Level 5

Hello Richard,

I would like the output as I showed above. That is, "CHANGE" should be 1 for 2007 (the year of change) and years after that (2008, 2009).

SS

PGStats
Opal | Level 21

A DO UNTIL loop will do the trick:

data have;

input TIC $ YEAR CEO$;

datalines;

A     2005     Frank

A     2006     Frank

A     2007     TOD

A     2008     TOD

A     2009     TOD

;

data want;

nCEO = 0;

do until (last.TIC);

  set have; by TIC CEO notsorted;

  nCEO + first.CEO;

  CHANGE = nCEO > 1;

  output;

  end;

drop nCEO;

run;

 

proc print data=want noobs; run;

PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 563 views
  • 3 likes
  • 3 in conversation