<?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 Lookup table and fill in missing values (ACS data)? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753570#M80773</link>
    <description>&lt;P class="p1"&gt;I have two tables, first and second, that contains data from the American Community Survey (ACS). The first table has missing values (always across 4 variables), whereas the second table contains values I wish to fill in for the missing values in the first table (through matching/joining by PAT_ID).&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ACS variables at census block level */
data first;
input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@;
datalines;
1 45810 93.82 13.07 9.32
2 35264 54.94 27.81 4.76
3 . . . .&amp;nbsp;
4 . . . .&amp;nbsp;
5 42346 18.62 1.87 1.29
6 42346 41.11 4.76 10.29
7 250001 41.11 3.02 1.29
8 115290 93.82 27.81 1.87
9 215493 21.65 10.29 3.60
10 . . . .&amp;nbsp;
11 215493 15.61 27.81 3.02
12 77521 18.62 7.17 9.32
13 215493 54.94 5.95 27.81
14 . . . .&amp;nbsp;
15 115290 34.35 1.29 9.32
16 30872 34.35 10.29 7.17
17 105039 15.61 4.76 13.07
18 . . . .&amp;nbsp;&amp;nbsp;
19 38964 9.55 4.76 2.45
20 38964 54.94 10.29 10.29
;

/* variables at the zipcode level (INCOME_ZIPCODE EDU_ZIPCODE UNEMPLOY_ZIPCODE HOMEOWNER_ZIPCODE)
 but named the same as above to help with merging*/ 
data second; 
input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@; 
datalines; 
1 50127 8.33 35.00 82.71 
2 43578 29.01 44.06 58.68 
3 36251 14.93 50.14 62.01 
4 136686 14.93 29.44 67.86 
5 136686 22.49 33.52 87.99 
6 43578 22.49 50.14 87.99 
7 32374 10.86 33.52 64.28 
8 39755 7.51 56.55 58.68 
9 34548 12.48 56.55 80.46 
10 34548 14.93 38.84 58.68 
11 50127 72.73 31.91 82.71 
12 50127 9.22 50.14 87.99 
13 37981 14.93 44.06 75.23 
14 61270 8.33 41.37 87.99 
15 57101 8.33 50.14 80.46 
16 36251 4.79 38.84 62.01 
17 136686 8.33 48.14 80.46 
18 37981 72.73 31.91 67.86 
19 50127 9.22 33.52 62.01 
20 136686 19.81 41.37 62.01 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* values filled in for missing are from zip-code level instead of census block level&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;data want;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@;
datalines;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;1 45810 93.82 13.07 9.32&lt;BR /&gt;2 35264 54.94 27.81 4.76&lt;BR /&gt;3&amp;nbsp;36251 14.93 50.14 62.01&amp;nbsp;&lt;BR /&gt;4&amp;nbsp;136686 14.93 29.44 67.86 &lt;BR /&gt;5 42346 18.62 1.87 1.29&lt;BR /&gt;6 42346 41.11 4.76 10.29&lt;BR /&gt;7 250001 41.11 3.02 1.29&lt;BR /&gt;8 115290 93.82 27.81 1.87&lt;BR /&gt;9 215493 21.65 10.29 3.60&lt;BR /&gt;10&amp;nbsp;34548 14.93 38.84 58.68&amp;nbsp;&lt;BR /&gt;11 215493 15.61 27.81 3.02&lt;BR /&gt;12 77521 18.62 7.17 9.32&lt;BR /&gt;13 215493 54.94 5.95 27.81&lt;BR /&gt;14&amp;nbsp;61270 8.33 41.37 87.99 &lt;BR /&gt;15 115290 34.35 1.29 9.32&lt;BR /&gt;16 30872 34.35 10.29 7.17&lt;BR /&gt;17 105039 15.61 4.76 13.07&lt;BR /&gt;18 37981 72.73 31.91 67.86 &amp;nbsp;&lt;BR /&gt;19 38964 9.55 4.76 2.45&lt;BR /&gt;20 38964 54.94 10.29 10.29&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 20:12:00 GMT</pubDate>
    <dc:creator>PharmlyDoc</dc:creator>
    <dc:date>2021-07-12T20:12:00Z</dc:date>
    <item>
      <title>Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753570#M80773</link>
      <description>&lt;P class="p1"&gt;I have two tables, first and second, that contains data from the American Community Survey (ACS). The first table has missing values (always across 4 variables), whereas the second table contains values I wish to fill in for the missing values in the first table (through matching/joining by PAT_ID).&lt;/P&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ACS variables at census block level */
data first;
input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@;
datalines;
1 45810 93.82 13.07 9.32
2 35264 54.94 27.81 4.76
3 . . . .&amp;nbsp;
4 . . . .&amp;nbsp;
5 42346 18.62 1.87 1.29
6 42346 41.11 4.76 10.29
7 250001 41.11 3.02 1.29
8 115290 93.82 27.81 1.87
9 215493 21.65 10.29 3.60
10 . . . .&amp;nbsp;
11 215493 15.61 27.81 3.02
12 77521 18.62 7.17 9.32
13 215493 54.94 5.95 27.81
14 . . . .&amp;nbsp;
15 115290 34.35 1.29 9.32
16 30872 34.35 10.29 7.17
17 105039 15.61 4.76 13.07
18 . . . .&amp;nbsp;&amp;nbsp;
19 38964 9.55 4.76 2.45
20 38964 54.94 10.29 10.29
;

/* variables at the zipcode level (INCOME_ZIPCODE EDU_ZIPCODE UNEMPLOY_ZIPCODE HOMEOWNER_ZIPCODE)
 but named the same as above to help with merging*/ 
data second; 
input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@; 
datalines; 
1 50127 8.33 35.00 82.71 
2 43578 29.01 44.06 58.68 
3 36251 14.93 50.14 62.01 
4 136686 14.93 29.44 67.86 
5 136686 22.49 33.52 87.99 
6 43578 22.49 50.14 87.99 
7 32374 10.86 33.52 64.28 
8 39755 7.51 56.55 58.68 
9 34548 12.48 56.55 80.46 
10 34548 14.93 38.84 58.68 
11 50127 72.73 31.91 82.71 
12 50127 9.22 50.14 87.99 
13 37981 14.93 44.06 75.23 
14 61270 8.33 41.37 87.99 
15 57101 8.33 50.14 80.46 
16 36251 4.79 38.84 62.01 
17 136686 8.33 48.14 80.46 
18 37981 72.73 31.91 67.86 
19 50127 9.22 33.52 62.01 
20 136686 19.81 41.37 62.01 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* values filled in for missing are from zip-code level instead of census block level&amp;nbsp; &amp;nbsp;*/&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;data want;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;input PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK @@;
datalines;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;1 45810 93.82 13.07 9.32&lt;BR /&gt;2 35264 54.94 27.81 4.76&lt;BR /&gt;3&amp;nbsp;36251 14.93 50.14 62.01&amp;nbsp;&lt;BR /&gt;4&amp;nbsp;136686 14.93 29.44 67.86 &lt;BR /&gt;5 42346 18.62 1.87 1.29&lt;BR /&gt;6 42346 41.11 4.76 10.29&lt;BR /&gt;7 250001 41.11 3.02 1.29&lt;BR /&gt;8 115290 93.82 27.81 1.87&lt;BR /&gt;9 215493 21.65 10.29 3.60&lt;BR /&gt;10&amp;nbsp;34548 14.93 38.84 58.68&amp;nbsp;&lt;BR /&gt;11 215493 15.61 27.81 3.02&lt;BR /&gt;12 77521 18.62 7.17 9.32&lt;BR /&gt;13 215493 54.94 5.95 27.81&lt;BR /&gt;14&amp;nbsp;61270 8.33 41.37 87.99 &lt;BR /&gt;15 115290 34.35 1.29 9.32&lt;BR /&gt;16 30872 34.35 10.29 7.17&lt;BR /&gt;17 105039 15.61 4.76 13.07&lt;BR /&gt;18 37981 72.73 31.91 67.86 &amp;nbsp;&lt;BR /&gt;19 38964 9.55 4.76 2.45&lt;BR /&gt;20 38964 54.94 10.29 10.29&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753570#M80773</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-07-12T20:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753615#M80774</link>
      <description>&lt;P&gt;Assuming you don't have duplicate PAT_IDs in your SECOND dataset, this works, using a&amp;nbsp;LEFT JOIN and COALESCE():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table want as
    select f.pat_id
          ,coalesce(f.income_block, s.income_block) as income_block
          ,coalesce(f.edu_block, s.edu_block) as edu_block
          ,coalesce(f.unemploy_block, s.unemploy_block) as unemploy_block
          ,coalesce(f.homeowner_block, s.homeowner_block) as homeowner_block
    from first f
    left join second s
        on f.pat_id = s.pat_id;
quit;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 20:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753615#M80774</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2021-07-12T20:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753620#M80775</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alright, here is the code that I used to solved my question.&amp;nbsp;&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 coalesce(a.PAT_ID, b.PAT_ID) as PAT_ID, coalesce(a.INCOME_BLOCK,b.INCOME_BLOCK) AS INCOME_BLOCK,
coalesce(a.EDU_BLOCK,b.EDU_BLOCK) AS EDU_BLOCK,
coalesce(a.UNEMPLOY_BLOCK,b.UNEMPLOY_BLOCK) AS UNEMPLOY_BLOCK,
coalesce(a.HOMEOWNER_BLOCK,b.HOMEOWNER_BLOCK) AS HOMEOWNER_BLOCK
            FROM first a LEFT JOIN second b
                ON a.PAT_ID = b.PAT_ID;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I'm having trouble doing the same as above but with additional variables in the first dataset such as sex and age.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data third; 
input PAT_ID : best2. SEX :$6. AGE : best2. INCOME_BLOCK : best6. EDU_BLOCK : best4. UNEMPLOY_BLOCK : best4. HOMEOWNER_BLOCK : best4. ;
datalines;
1 Female  22 45810 93.82 13.07 9.32
2 Male   37  35264 54.94 27.81 4.76
3 Male 27     .     .     .    . 
4 Male 37     .     .     .    .
5 Female 27 42346  18.62 1.87 1.29
6 Male   28 42346  41.11 4.76 10.29
7 Female  23 250001 41.11 3.02 1.29
8 Female  21 115290 93.82 27.81 1.87
9 Female  43 215493 21.65 10.29 3.60
10 Male	 35     .     .     .    .
11 Male	 30 215493 15.61 27.81 3.02
12 Male	 21 77521  18.62 7.17  9.32
13 Male	 21 215493 54.94 5.95  27.81
14 Male	 28     .     .     .    .
15 Male	 34 115290 34.35 1.29  9.32
16 Male	 38 30872  34.35 10.29 7.17
17 Female  36 105039 15.61 4.76 13.07
18 Female 23    .     .     .    .
19 Female 34 38964 9.55	 4.76  2.45
20 Female 26 38964 54.94 10.29 10.29
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 21:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753620#M80775</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-07-12T21:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753622#M80776</link>
      <description>&lt;P&gt;What about if I have other variables in the first dataset that aren't in the second dataset (e.g. SEX, AGE, and a dozen more)&amp;nbsp; that I want to include in the want dataset?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 21:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753622#M80776</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-07-12T21:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753638#M80777</link>
      <description>&lt;P&gt;Here's the easy way.&amp;nbsp; It assumes that both data sets are sorted, and that your data sets have just one observation per PAT_ID.&amp;nbsp; (Mismatches are OK.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   update second first;
   by pad_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For each PAT_ID, it takes data from your second data set, then replaces those values with any non-missing values from the first data set.&amp;nbsp; That's a little convoluted, but sounds like it's exactly what you need.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 23:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753638#M80777</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-07-12T23:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753653#M80778</link>
      <description>&lt;P&gt;Actually, I should have elaborated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In reality my second data set has 250,000 patients, whereas the first dataset has only 100,000.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The update statement in the data step that you mentioned gives me a table with 250,000 patients, when I only want the 100,000&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 03:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753653#M80778</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-07-13T03:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753714#M80779</link>
      <description>&lt;P&gt;A small tweak to the program should take care of that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   update second first (in=original_100k);
   by pat_id;
   if original_100k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jul 2021 08:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753714#M80779</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-07-13T08:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753797#M80780</link>
      <description>&lt;P&gt;What's your source for this? Does SAS have any references to using the update statement in this manner?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than this source:&amp;nbsp;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/5184-2020.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/5184-2020.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And how do I maintain the original column order from the first dataset?&lt;/P&gt;
&lt;P&gt;PAT_ID SEX AGE INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PAT_ID INCOME_BLOCK EDU_BLOCK UNEMPLOY_BLOCK HOMEOWNER_BLOCK&amp;nbsp;SEX AGE&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 15:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753797#M80780</guid>
      <dc:creator>PharmlyDoc</dc:creator>
      <dc:date>2021-07-13T15:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup table and fill in missing values (ACS data)?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753857#M80782</link>
      <description>&lt;P&gt;There's no source other than what you have (likely) see already.&amp;nbsp; It's the documentation on what the UPDATE statement does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To keep the variables in the order of the first data set, here's a trick you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if 5=4 then set first;
   update second first (in=original_100k);
   by pat_id;
   if original_100k;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since 5 will never equal 4, the SET statement never executes.&amp;nbsp; But its presence is enough to define all the variables in FIRST at that point in the code.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jul 2021 18:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Lookup-table-and-fill-in-missing-values-ACS-data/m-p/753857#M80782</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-07-13T18:24:54Z</dc:date>
    </item>
  </channel>
</rss>

