<?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: Setting the values of a column for all members of a by variable group to the value of first in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600597#M173645</link>
    <description>&lt;P&gt;Perhaps your thought process was after this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=_have(rename=(zip=z) keep=id zip);
by id descending year;
run;

data want;
 merge have(drop=zip) _have;
 by id;
 retain zip;
 if first.id then zip=z;
 drop z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Oct 2019 00:01:15 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-31T00:01:15Z</dc:date>
    <item>
      <title>Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600589#M173641</link>
      <description>&lt;P&gt;I have a list of zip codes associated with IDs and years, and the zip codes for a given ID can be different for each year:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; zip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; year&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to make it so that the zip code for a given ID is set to the zip code appearing in the most recent year:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; zip&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; year&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2018&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have done is try sort by ID and year, but I am lost as to how to move forward with the rest of the logic. I suspect I need to use the first. function, but beyond that I am having no luck.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 23:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600589#M173641</guid>
      <dc:creator>aljones1816</dc:creator>
      <dc:date>2019-10-30T23:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600590#M173642</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297580"&gt;@aljones1816&lt;/a&gt;&amp;nbsp; &amp;nbsp;Welcome to SAS communities, here is a proc sql welcome for you&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID        zip        year	;
cards;
1         2           2018 
1         3           2017
1         2           2018
1         3           2017
;

proc sql;
create table want as
select ID, max(t) as zip,year
from (select ID, zip,year, (year=max(year))*zip as t from have group by id)
group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 01:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600590#M173642</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-31T01:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600593#M173643</link>
      <description>&lt;P&gt;And a Datastep solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID        zip        year	;
cards;
1         2           2018 
1         3           2017
1         2           2018
1         3           2017
;

data want;
 do _n_=1 by 1 until(last.id);
  set have;
  by id;
  _m=_m max year;
  if _m=year then _z=zip;
 end;
 do _n_=1 to _n_;
  set have;
  zip=_z;
  output;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Oct 2019 23:44:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600593#M173643</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-30T23:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600597#M173645</link>
      <description>&lt;P&gt;Perhaps your thought process was after this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=_have(rename=(zip=z) keep=id zip);
by id descending year;
run;

data want;
 merge have(drop=zip) _have;
 by id;
 retain zip;
 if first.id then zip=z;
 drop z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Oct 2019 00:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600597#M173645</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-31T00:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600866#M173750</link>
      <description>&lt;P&gt;I see you have multiple observations for the highest year within an ID.&amp;nbsp; In your sample ID 1 have 2 records for 2018.&amp;nbsp; They both have zip=2.&amp;nbsp; Can you assume that the zip code will be constant across all highest year records within an ID? &amp;nbsp; If not, then what rule would you use to choose a zip value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 00:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/600866#M173750</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-01T00:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Setting the values of a column for all members of a by variable group to the value of first</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/602865#M174600</link>
      <description>&lt;P&gt;Thanks so much,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;! I tried all of your solutions and each worked beautifully. I chose this as the answer only because it was the option I ultimately stuck with in my code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2019 20:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-the-values-of-a-column-for-all-members-of-a-by-variable/m-p/602865#M174600</guid>
      <dc:creator>aljones1816</dc:creator>
      <dc:date>2019-11-08T20:36:29Z</dc:date>
    </item>
  </channel>
</rss>

