<?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: Filling empty cell with others cells of the same column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758571#M239543</link>
    <description>&lt;P&gt;Below one way to go (in case of multiple email addresses will only pick one per name and state).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (name state email) ($);
  datalines;
name1,state1,email1
name1,state2,
name1,state1,
name1,state2,email2
;

proc sort data=have out=have_sorted;
  by name state DESCENDING email ;
run;

data want;
  set have_sorted;
  by name state;
  retain r_email;
  if first.state then r_email=email;
  else email=r_email;
  drop r_email;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 31 Jul 2021 01:41:24 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-07-31T01:41:24Z</dc:date>
    <item>
      <title>Filling empty cell with others cells of the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758538#M239516</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to complete de empty cells of column Email with those already existing if they have the same name and stay in the same state.&lt;/P&gt;&lt;P&gt;I tried with If then do to create another column and fill it out, but it doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, is there a way to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ElodieT_1-1627679583926.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62159i43E95325879B4EA8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ElodieT_1-1627679583926.png" alt="ElodieT_1-1627679583926.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 21:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758538#M239516</guid>
      <dc:creator>ElodieT</dc:creator>
      <dc:date>2021-07-30T21:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filling empty cell with others cells of the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758543#M239520</link>
      <description>&lt;P&gt;In the future, do not provide your data as a screen capture, because we can't work with screen captures and provide tested code. Instead, please provide data as SAS data step code, instructions are here: &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt; and then we can actually use your data and create tested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a possible solution (UNTESTED)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table has_email as select * from have where not missing(email);
    create table want as select a.*,coalescec(a.email,b.email) from have a left join has_email b
         on a.full_name=b.full_name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jul 2021 21:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758543#M239520</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-30T21:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Filling empty cell with others cells of the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758556#M239532</link>
      <description>&lt;P&gt;And what if a given name/state combination has more than one non-blank email value?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 22:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758556#M239532</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-30T22:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Filling empty cell with others cells of the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758571#M239543</link>
      <description>&lt;P&gt;Below one way to go (in case of multiple email addresses will only pick one per name and state).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (name state email) ($);
  datalines;
name1,state1,email1
name1,state2,
name1,state1,
name1,state2,email2
;

proc sort data=have out=have_sorted;
  by name state DESCENDING email ;
run;

data want;
  set have_sorted;
  by name state;
  retain r_email;
  if first.state then r_email=email;
  else email=r_email;
  drop r_email;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Jul 2021 01:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758571#M239543</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-07-31T01:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Filling empty cell with others cells of the same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758610#M239561</link>
      <description>&lt;P&gt;This code builds a lookup table in a hash memory-resident object.&amp;nbsp; Then it uses it to populate missing emails for a given full_name/state.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested in the absence of sample data in the form of a working data step:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  if _n_=1 then do;
    declare hash h (dataset:'have (where=(not missing(email)) keep=full_name state email)');
      h.definekey('full_name','state');
      h.definedata('email');
      h.definedone();
  end;
  if email=' ' then _rc=h.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If a given FULL_NAME/STATE has multiple observations with non-blank emails, this code retains the first one in the hash object (default behavior of the hash object).&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Jul 2021 20:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-empty-cell-with-others-cells-of-the-same-column/m-p/758610#M239561</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-31T20:21:05Z</dc:date>
    </item>
  </channel>
</rss>

