<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Identify change in the committee membership in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730164#M227332</link>
    <description>&lt;P&gt;You can read each firmid/year of data twice.&amp;nbsp; In the first pass, make an array of names, sort the array, then copy the names, separated by commas, to a single character variable (_this_year_names).&amp;nbsp; Then set the DIR_CHANGE dummy according to whether _this_year_names matches its own lagged value&amp;nbsp; (except for the first year of the id, when DIR_CHANGE is set to zero):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input firm_id $ year dirname $;
datalines;
A	2007	Jack	0
A	2007	Tom	0
A	2007	Linda	0
A	2008	Jack	1
A	2008	Tom	1
A	2008	Mary	1
B	2007	Jenny	0
B	2007	Jessy	0
B	2007	Joe	0
B	2008	Jenny	1
B	2008	Jessy	1
C	2007	Ally	0
C	2007	April	0
C	2008	Ally	0
C	2008	April	0
D	2007	Mark	0
D	2007	Frank	0
D	2008	Mark	1
D	2008	Frank	1
D	2008	Mike	1
run;

data want (drop=_:);

  array _dnames {20} $20;      /*One year of names in an array */
  length _this_year_names _last_year_names $400; /*One year as csv long character*/

  /* Read one year of names and populate the array*/
  do _n=1 by 1 until (last.year);
    set have;
    by firm_id year;
    if first.firm_id then dir_change=0; /*First first year only*/
    _dnames{_n}=dirname;
  end;

  /* Sort the array and copy a csv list into a character variable*/
  call sortc(of _dnames{*});
  _this_year_names=catx(',',of _dnames{*});
  _last_year_names=lag(_this_year_names);

  /* Compare to last year value*/
  if dir_change=. then dir_change=(_this_year_names ^= _last_year_names);

  /* Re-read the year and output */
  do until (last.year);
    set have;
    by firm_id year;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just make sure the array size (20 above) accommodates all the names for a single year.&amp;nbsp; And make sure the length of the _this_year_names &amp;amp; _last_year_names ($400 above) is enough to contain all the names, separated by commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the sorting of the names will put blank names (i.e. if your only have 15 names in a year, youll have 5 blanks) first, followed by the actual names.&amp;nbsp; This won't matter for the task as you describe it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And of course make sure the each distinct name is consistent in its use of uppercase/lowercase.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Mar 2021 18:08:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-03-30T18:08:37Z</dc:date>
    <item>
      <title>Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730135#M227317</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset (20,000 + observations) that consists of firm identifier, year, and audit committee director names. I want to create a variable (Dir_change) if a new director joins or an existing member leaves the company (it is possible that in some cases the company may not hire a new director to replace the leaving director or hire an additional director to increase the number of members). So to give you an idea, this is how I want my dir_change variable to look.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Firm Identifier&lt;/TD&gt;&lt;TD&gt;Year&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Director&lt;/TD&gt;&lt;TD&gt;Dir_change&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2007&lt;/TD&gt;&lt;TD&gt;Jack&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&g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t;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2007&lt;/TD&gt;&lt;TD&gt;Frank&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2008&lt;/TD&gt;&lt;TD&gt;Mark&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2008&lt;/TD&gt;&lt;TD&gt;Frank&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2008&lt;/TD&gt;&lt;TD&gt;Mike&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above example, in company A, Linda is replacing Mary in 2008 and hence I want dir_Change to be 1 for that year. For company B, Joe left the board and hence I want the dir_Change to be 1. There was no change in the directors for company C and hence it is zero. For company D, although no one left the company, Mike joined the company in 2008 and hence I want dir_change to be 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am a newbie and know only basic coding so far. I would greatly appreciate it if someone shares the code that will help me get the desired output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;GokulK&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 16:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730135#M227317</guid>
      <dc:creator>GokulK</dc:creator>
      <dc:date>2021-03-30T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730148#M227324</link>
      <description>&lt;P&gt;Is it always two years for a firm? Or could the data contain more than two years, and then the solution ought to compare each year to the previous year? Or do you compare to the first year?&lt;BR /&gt;&lt;BR /&gt;What about spelling errors and capitalization differences? Are these all cleaned up beforehand?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 17:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730148#M227324</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-30T17:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730164#M227332</link>
      <description>&lt;P&gt;You can read each firmid/year of data twice.&amp;nbsp; In the first pass, make an array of names, sort the array, then copy the names, separated by commas, to a single character variable (_this_year_names).&amp;nbsp; Then set the DIR_CHANGE dummy according to whether _this_year_names matches its own lagged value&amp;nbsp; (except for the first year of the id, when DIR_CHANGE is set to zero):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input firm_id $ year dirname $;
datalines;
A	2007	Jack	0
A	2007	Tom	0
A	2007	Linda	0
A	2008	Jack	1
A	2008	Tom	1
A	2008	Mary	1
B	2007	Jenny	0
B	2007	Jessy	0
B	2007	Joe	0
B	2008	Jenny	1
B	2008	Jessy	1
C	2007	Ally	0
C	2007	April	0
C	2008	Ally	0
C	2008	April	0
D	2007	Mark	0
D	2007	Frank	0
D	2008	Mark	1
D	2008	Frank	1
D	2008	Mike	1
run;

data want (drop=_:);

  array _dnames {20} $20;      /*One year of names in an array */
  length _this_year_names _last_year_names $400; /*One year as csv long character*/

  /* Read one year of names and populate the array*/
  do _n=1 by 1 until (last.year);
    set have;
    by firm_id year;
    if first.firm_id then dir_change=0; /*First first year only*/
    _dnames{_n}=dirname;
  end;

  /* Sort the array and copy a csv list into a character variable*/
  call sortc(of _dnames{*});
  _this_year_names=catx(',',of _dnames{*});
  _last_year_names=lag(_this_year_names);

  /* Compare to last year value*/
  if dir_change=. then dir_change=(_this_year_names ^= _last_year_names);

  /* Re-read the year and output */
  do until (last.year);
    set have;
    by firm_id year;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just make sure the array size (20 above) accommodates all the names for a single year.&amp;nbsp; And make sure the length of the _this_year_names &amp;amp; _last_year_names ($400 above) is enough to contain all the names, separated by commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the sorting of the names will put blank names (i.e. if your only have 15 names in a year, youll have 5 blanks) first, followed by the actual names.&amp;nbsp; This won't matter for the task as you describe it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And of course make sure the each distinct name is consistent in its use of uppercase/lowercase.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 18:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730164#M227332</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-30T18:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730170#M227337</link>
      <description>&lt;P&gt;It is a 10-year data starting 2007. I would like to see if the committee composition changed compared to the previous year. That is, for instance, are the directors in the committee the same in 2019 as they were in 2018. Also, there is a possibility that a company may (1) lose more than one director in a year or (2) lose one and add two directors to their committee. I have capitalized all the names in my actual dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;GokulK&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 18:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730170#M227337</guid>
      <dc:creator>GokulK</dc:creator>
      <dc:date>2021-03-30T18:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730175#M227341</link>
      <description>&lt;P&gt;Here is a SQL solution involving a full join (always tricky):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input firm $ year name $;
datalines;
A   2007    Jack    0
A   2007    Tom 0
A   2007    Linda   0
A   2008    Jack    1
A   2008    Tom 1
A   2008    Mary    1
B   2007    Jenny   0
B   2007    Jessy   0
B   2007    Joe 0
B   2008    Jenny   1
B   2008    Jessy   1
C   2007    Ally    0
C   2007    April   0
C   2008    Ally    0
C   2008    April   0
D   2007    Mark    0
D   2007    Frank   0
D   2008    Mark    1
D   2008    Frank   1
D   2008    Mike    1
;

proc sql;
create table want as
select 
    h.*,
    coalesce(c.change, 0) as change
from
    have as h left join
    (
    select 
        coalesce(a.firm, b.firm) as firm,
        coalesce(a.year, b.year+1) as year,
        nmiss(a.firm) + nmiss(b.firm) &amp;gt; 0 as change
    from 
        have as a full join
        have as b on 
            a.firm=b.firm and 
            a.year=b.year+1 and 
            a.name=b.name
    group by calculated firm, calculated year
    having count(a.firm) &amp;gt; 0 and count(b.firm) &amp;gt; 0 ) as c
    on h.firm=c.firm and h.year=c.year;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1617129706716.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56673iBF4687820B06426A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1617129706716.png" alt="PGStats_0-1617129706716.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 18:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730175#M227341</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-03-30T18:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730282#M227373</link>
      <description>&lt;P&gt;Thank you everyone for providing me the codes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 01:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730282#M227373</guid>
      <dc:creator>GokulK</dc:creator>
      <dc:date>2021-03-31T01:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Identify change in the committee membership</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730384#M227435</link>
      <description>&lt;P&gt;Was there just two year ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input firm $ year name $;
datalines;
A   2007    Jack    0
A   2007    Tom 0
A   2007    Linda   0
A   2008    Jack    1
A   2008    Tom 1
A   2008    Mary    1
B   2007    Jenny   0
B   2007    Jessy   0
B   2007    Joe 0
B   2008    Jenny   1
B   2008    Jessy   1
C   2007    Ally    0
C   2007    April   0
C   2008    Ally    0
C   2008    April   0
D   2007    Mark    0
D   2007    Frank   0
D   2008    Mark    1
D   2008    Frank   1
D   2008    Mike    1
;

proc sql;
create table temp as
select distinct firm from
(
select firm,name,count(distinct year) as count
 from have
  group by firm,name
)
group by firm
having sum(count ne 2);

create table want as
select *,case when year=max(year) and firm in (select firm from temp) then 1 else 0 end as flag
 from have as a
  group by firm
   order by 1,2;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Mar 2021 12:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-change-in-the-committee-membership/m-p/730384#M227435</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-03-31T12:45:41Z</dc:date>
    </item>
  </channel>
</rss>

