<?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: New column with value by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759930#M240250</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input city :$20.	price;
cards;
Dresden	2005
Berlin	 
Frankfurt	 
Bonn	 
Berlin	4030
Bonn	 
Dresden	2005
Frankfurt	6053
Berlin	 
Frankfurt	 
Dresden	 
Bonn	 
Berlin	4030
Frankfurt	 
Bonn	3050
Dresden	 
;

data want;
 if _n_=1 then do;
  declare hash h(dataset:'have(where=(price2 is not missing) rename=(price=price2))');
  h.definekey('city');
  h.definedata('price2');
  h.definedone();
 end;
set have;
call missing(price2);
rc=h.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Aug 2021 13:01:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-08-06T13:01:29Z</dc:date>
    <item>
      <title>New column with value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759916#M240244</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ive a dataset with a column "city" (each city exists multiple times) and a column with "prices" (€, sometimes also multiple times, but always the same price). In the price-coulumn there are many empty cells. What I want is to fill the empty cells with the city specific prices. How is this doable? Maybe with Alter table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 120pt;" border="0" width="160" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" class="xl65" style="height: 12.0pt; width: 60pt;"&gt;&lt;STRONG&gt;city&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px" class="xl65" style="width: 60pt;"&gt;&lt;STRONG&gt;price&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px" align="right"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px" align="right"&gt;6053&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px" align="right"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px" align="right"&gt;3050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="79.8667px" height="12px" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD width="79.1333px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;....n&lt;/TD&gt;
&lt;TD&gt;....&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 180pt;" border="0" width="240" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="80" height="16" class="xl65" style="height: 12.0pt; width: 60pt;"&gt;&lt;STRONG&gt;city&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" class="xl65" style="width: 60pt;"&gt;&lt;STRONG&gt;price&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80" class="xl65" style="width: 60pt;"&gt;&lt;STRONG&gt;price2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD align="right"&gt;2005&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;6053&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;3050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD&gt;4030&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;3050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD&gt;2005&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD align="right"&gt;6053&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;6053&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;6053&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;3050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Berlin&lt;/TD&gt;
&lt;TD align="right"&gt;4030&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;4030&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Frankfurt&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;6053&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Bonn&lt;/TD&gt;
&lt;TD align="right"&gt;3050&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;3050&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD height="16" style="height: 12.0pt;"&gt;Dresden&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl66"&gt;2005&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;...n&lt;/TD&gt;
&lt;TD&gt;....&lt;/TD&gt;
&lt;TD&gt;....&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thank you for help!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 12:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759916#M240244</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-08-06T12:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: New column with value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759920#M240246</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as select a.*,b.price as price2 from
    have as a left join (select city,max(price) as price from have group by city) as b
    on a.city=b.city;
quit;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want tested code (and this is always a good idea anyway,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388612"&gt;@Konkordanz&lt;/a&gt;&amp;nbsp;) provide the data as SAS data step code&amp;nbsp; (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;) and not as a screen capture, something you should just do automatically, every time you ask a question; and from now on we will expect data in this form and not as screen captures.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 12:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759920#M240246</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-06T12:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: New column with value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759930#M240250</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input city :$20.	price;
cards;
Dresden	2005
Berlin	 
Frankfurt	 
Bonn	 
Berlin	4030
Bonn	 
Dresden	2005
Frankfurt	6053
Berlin	 
Frankfurt	 
Dresden	 
Bonn	 
Berlin	4030
Frankfurt	 
Bonn	3050
Dresden	 
;

data want;
 if _n_=1 then do;
  declare hash h(dataset:'have(where=(price2 is not missing) rename=(price=price2))');
  h.definekey('city');
  h.definedata('price2');
  h.definedone();
 end;
set have;
call missing(price2);
rc=h.find();
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Aug 2021 13:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/759930#M240250</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-06T13:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: New column with value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/760324#M240424</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;: Thank you! Both are practial solutions!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 07:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-column-with-value-by-group/m-p/760324#M240424</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-08-09T07:50:16Z</dc:date>
    </item>
  </channel>
</rss>

