<?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 Filling in blank values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664438#M198496</link>
    <description>&lt;P&gt;I have a table with office locations, with each office having separate locations.&amp;nbsp; Each of these locations should have a county associated with them, but not all do.&amp;nbsp; How can I fill in/impute those missing counties for the locations based on the county of the other locations in the same office?&amp;nbsp; For those missing, I want to fill in the associated county info as well.&amp;nbsp; However,&amp;nbsp; if an office is associated with more than 1 county in the original data, then I want to leave the missing values in that office as be.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Office&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Location&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County_Name&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County_Population&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;25&lt;/TD&gt;
&lt;TD&gt;Harris&lt;/TD&gt;
&lt;TD align="right"&gt;500000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;25&lt;/TD&gt;
&lt;TD&gt;Harris&lt;/TD&gt;
&lt;TD align="right"&gt;500000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;19&lt;/TD&gt;
&lt;TD&gt;Bradley&lt;/TD&gt;
&lt;TD align="right"&gt;200000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;20&lt;/TD&gt;
&lt;TD&gt;Orange&lt;/TD&gt;
&lt;TD align="right"&gt;700000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&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;I want to fill in the values for Office A, but NOT Office B due to the ambiguity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly prefer a method which is easily reproducible when the base data is updated.&amp;nbsp; No manual input.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jun 2020 18:56:07 GMT</pubDate>
    <dc:creator>RandoDando</dc:creator>
    <dc:date>2020-06-23T18:56:07Z</dc:date>
    <item>
      <title>Filling in blank values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664438#M198496</link>
      <description>&lt;P&gt;I have a table with office locations, with each office having separate locations.&amp;nbsp; Each of these locations should have a county associated with them, but not all do.&amp;nbsp; How can I fill in/impute those missing counties for the locations based on the county of the other locations in the same office?&amp;nbsp; For those missing, I want to fill in the associated county info as well.&amp;nbsp; However,&amp;nbsp; if an office is associated with more than 1 county in the original data, then I want to leave the missing values in that office as be.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 240pt;" border="0" width="320" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Office&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Location&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County_Name&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;County_Population&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;25&lt;/TD&gt;
&lt;TD&gt;Harris&lt;/TD&gt;
&lt;TD align="right"&gt;500000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;25&lt;/TD&gt;
&lt;TD&gt;Harris&lt;/TD&gt;
&lt;TD align="right"&gt;500000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;19&lt;/TD&gt;
&lt;TD&gt;Bradley&lt;/TD&gt;
&lt;TD align="right"&gt;200000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;20&lt;/TD&gt;
&lt;TD&gt;Orange&lt;/TD&gt;
&lt;TD align="right"&gt;700000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;.&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&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;I want to fill in the values for Office A, but NOT Office B due to the ambiguity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly prefer a method which is easily reproducible when the base data is updated.&amp;nbsp; No manual input.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 18:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664438#M198496</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2020-06-23T18:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in blank values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664448#M198501</link>
      <description>&lt;P&gt;Try next, not tested, code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have (where=(county ne .))
          out=tmp1 nodupkey;
  by office county;
run;

data tmp2;
 set tmp1;
  by office;
     if first.office and last.office; /* only one county */
	 rename county = tofill;
run;

data want;
 merge have(in=inh)
       tmp2 (in=int);
	by office;
	if inh and int &lt;BR /&gt;     and county = . then county = tofill;
	drop tofill;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jun 2020 19:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664448#M198501</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-06-23T19:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in blank values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664583#M198581</link>
      <description>&lt;P&gt;You can do it in one data step with a double do loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=" " dsd truncover;
input Office $ Location County County_Name :$20. County_Population;
datalines;
A 1 25 Harris 500000
A 2 25 Harris 500000
A 3 .  .
B 1 19 Bradley 200000
B 2 20 Orange 700000
B 3 .  .
;

data want;
length _county_name $20;
do until (last.office);
  set have;
  by office;
  if first.office then _flag = 1;
  if _flag and _county_name = " " and county_name ne " "
  then do;
    _county_name = county_name;
    _county = county;
  end;
  if county_name ne "" and county_name ne _county_name then _flag = 0;
end;
do until (last.office);
  set have;
  by office;
  if _flag and county_name = " "
  then do;
    county_name = _county_name;
    county = _county;
  end;
  output;
end;
drop _:;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                                County_      County_
Office    Location    County     Name      Population
  A           1         25      Harris       500000  
  A           2         25      Harris       500000  
  A           3         25      Harris            .  
  B           1         19      Bradley      200000  
  B           2         20      Orange       700000  
  B           3          .                        .  &lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jun 2020 08:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664583#M198581</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-24T08:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in blank values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664586#M198583</link>
      <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select a.OFFICE
       , a.LOCATION
       , coalesce(a.COUNTY,b.COUNTY) as COUNTY
       , coalesce(a.COUNTY_NAME,b.COUNTY_NAME) as COUNTY_NAME
       , coalesce(a.COUNTY_POPULATION,b.COUNTY_POPULATION) as COUNTY_POPULATION
  from HAVE a
    left join
      ( select unique OFFICE, COUNTY, COUNTY_NAME, COUNTY_POPULATION 
        from HAVE 
        where COUNTY 
        group by OFFICE 
        having count(unique COUNTY)=1 ) b
    on a.OFFICE=b.OFFICE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 08:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664586#M198583</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-24T08:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Filling in blank values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664614#M198589</link>
      <description>&lt;PRE&gt;data have;
infile datalines dlm=" " dsd truncover;
input Office $ Location County County_Name :$20. County_Population;
datalines;
A 1 25 Harris 500000
A 2 25 Harris 500000
A 3 .  .
B 1 19 Bradley 200000
B 2 20 Orange 700000
B 3 .  .
;

proc sql;
create table want as
select *,
 case when count(distinct county_name)=1 then max(county)
  else county end as new_county,
 case when count(distinct county_name)=1 then max(county_name)
  else county_name end as new_county_name
 from have
  group by office
   order by 1,2;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jun 2020 11:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filling-in-blank-values/m-p/664614#M198589</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-24T11:41:33Z</dc:date>
    </item>
  </channel>
</rss>

