<?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: One to Many Merge Retain The &amp;quot;Many&amp;quot; Observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406512#M98990</link>
    <description>Your scenario works but does not retain values for company, line when the&lt;BR /&gt;other vars are set to 0.&lt;BR /&gt;</description>
    <pubDate>Mon, 23 Oct 2017 13:28:57 GMT</pubDate>
    <dc:creator>mmattison</dc:creator>
    <dc:date>2017-10-23T13:28:57Z</dc:date>
    <item>
      <title>One to Many Merge Retain The "Many" Observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406486#M98979</link>
      <description>&lt;P&gt;I am merging two data sets.&amp;nbsp;My report data&amp;nbsp;has company, line, zip and 8 numerical variables (107 obs).&amp;nbsp;The zip in report data is only a&lt;STRONG&gt; partial&lt;/STRONG&gt; list for a given state. The&amp;nbsp;template data set has&lt;STRONG&gt; all&lt;/STRONG&gt; the&amp;nbsp;zips for that state (1071 obs). The desired result after merging the two data sets&amp;nbsp;"by zip" is the report data with company, line and 8 numerical&amp;nbsp;variables and &lt;STRONG&gt;all zips&lt;/STRONG&gt; in the template data set with company and line&amp;nbsp;appearing on each observation with zeros in numeric variables (1071 obs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I merge, I am&amp;nbsp;getting blank company, line for data not in template.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help please!&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406486#M98979</guid>
      <dc:creator>mmattison</dc:creator>
      <dc:date>2017-10-23T12:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: One to Many Merge Retain The "Many" Observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406489#M98981</link>
      <description>&lt;P&gt;Please post example data. Use the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to create datasteps from your datasets, and post those in a code window (6th {i} or 7th "little running man" icons above the posting window, see &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;Also post your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406489#M98981</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T12:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: One to Many Merge Retain The "Many" Observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406491#M98982</link>
      <description>&lt;P&gt;Here's a quick code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input company $ zip $ var1 var2;
cards;
A 123456 1 1
B 123457 2 2
;
run;

data zips;
input zip $;
cards;
123456
123457
123458
;
run;

data want;
merge
  have (in=_have)
  zips (in=_zip)
;
by zip;
if not _have
then do;
  var1 = 0;
  var2 = 0;
end;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;company     zip      var1    var2

   A       123456      1       1 
   B       123457      2       2 
           123458      0       0 
&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 12:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406491#M98982</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T12:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: One to Many Merge Retain The "Many" Observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406512#M98990</link>
      <description>Your scenario works but does not retain values for company, line when the&lt;BR /&gt;other vars are set to 0.&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Oct 2017 13:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406512#M98990</guid>
      <dc:creator>mmattison</dc:creator>
      <dc:date>2017-10-23T13:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: One to Many Merge Retain The "Many" Observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406523#M98991</link>
      <description>&lt;P&gt;After reading your initial post again, I think you want a cartesian product with all the zips?&lt;/P&gt;
&lt;P&gt;In this case it is an issue for proc sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  a.company,
  b.zip as zip,
  case when b.zip = a.zip
    then var1
    else 0
  end as var1,
  case when b.zip = a.zip
    then var2
    else 0
  end as var2
from have a, zips b
order by company, zip
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(using my example data from the other post)&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 13:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-to-Many-Merge-Retain-The-quot-Many-quot-Observations/m-p/406523#M98991</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T13:48:26Z</dc:date>
    </item>
  </channel>
</rss>

