<?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: Merge Data with Replacement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727917#M226472</link>
    <description>&lt;P&gt;So you have one NC+SC dataset and one NC dataset and one SC dataset.&amp;nbsp; You want to add the NC and SC specific fields to the NC+SC dataset.&amp;nbsp; So you need to have key variable(s) in that uniquely identifies the observations in the NC dataset so you can merge. Similarly for the SC dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to merge the NC+SC with the NC dataset by whatever the key variable is.&lt;/P&gt;
&lt;P&gt;Then merge the result with the SC dataset by whatever the key variable is for that merge.&amp;nbsp; Note that you need re-sort the intermediate result first if you are using data step merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take care that the variables are you are trying to add from the NC and SC dataset do not use the same names.&lt;/P&gt;</description>
    <pubDate>Sat, 20 Mar 2021 16:28:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-20T16:28:47Z</dc:date>
    <item>
      <title>Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727573#M226316</link>
      <description>&lt;P&gt;I have two datasets. One is every county in NC (with the FIPS code) and the "matching" SC county. Some SC counties are are included multiple time in this dataset. In the second dataset, I have COVID-19 cases and deaths for every county in both states for everyday in 2020. I need to merge the datasets in a way that keeps the same frequency of counties as the first dataset for every day in 2020. So far, everything I try drops the repeated SC observations. Below is a representation of the code I've been trying.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*Sort; 
proc sort data = coviddata;
	by FIPS;
run;

proc sort data = PSdata;
	by FIPS;
run;


*Merge case and PS data into one dataset;
data try;
	merge PSdata coviddata ;
	by FIPS;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727573#M226316</guid>
      <dc:creator>romanbilan99</dc:creator>
      <dc:date>2021-03-18T21:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727575#M226317</link>
      <description>That's weird, the default behaviour is usually to include the multiple records. &lt;BR /&gt;Can you provide a small data example that illustrates this behaviour? Fake data is fine. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727575#M226317</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-18T21:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727576#M226318</link>
      <description>&lt;P&gt;If you have multiple values of a BY variable in &lt;STRONG&gt;only&lt;/STRONG&gt; one set then you will get multiple records in the output for matches. Period.&lt;/P&gt;
&lt;P&gt;You would have to show some example data that "gets dropped" for us to diagnose. Provide data in the form of a data step.&lt;/P&gt;
&lt;P&gt;Most likely cause is values not as you expect or a more complex merge on multiple variables with multiple values in both sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to get "same frequency" you have to decide what to do with the multiple records. Since you have "everyday in 2020" then you likely want some sort of summary. So you could either summarize one set before the merge or after the merge.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 21:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727576#M226318</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-18T21:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727877#M226450</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;in the county dataset there are 89 observations for NC and 89 for SC. In the COVID dataset there are 100 NC observations and 46 SC observations for everyday. When I try to merge, I get 89 NC observations and 33 SC observations after clearing any excess matches. And I just went ahead and attached the three actual datasets.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 22:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727877#M226450</guid>
      <dc:creator>romanbilan99</dc:creator>
      <dc:date>2021-03-19T22:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727880#M226452</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I included some fake data below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;County data
FIPS    Name     State  Indicator 
x          xx           NC     1
w          ww           NC    1
y          yy          SC      0
z         zz            SC      0
z         zz            SC      0

COVID data
FIPS    Name     State  Day   Cases
x          xx           NC     3/1     5
w          ww           NC     3/1      6
y          yy          SC      3/1      14
z         zz            SC      3/1     4
 
Combined data
FIPS    Name     State  Day   Cases Indicator
x          xx           NC     3/1     5           1
w          ww           NC     3/1      6       1
y          yy          SC      3/1      14       0
z         zz            SC      3/1     4         0&lt;/PRE&gt;&lt;P&gt;Notice county ZZ did not repeat in the combined data set. And when it comes to the repeated counties, I just want to attach their COVID data for that day to them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 22:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727880#M226452</guid>
      <dc:creator>romanbilan99</dc:creator>
      <dc:date>2021-03-19T22:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Data with Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727917#M226472</link>
      <description>&lt;P&gt;So you have one NC+SC dataset and one NC dataset and one SC dataset.&amp;nbsp; You want to add the NC and SC specific fields to the NC+SC dataset.&amp;nbsp; So you need to have key variable(s) in that uniquely identifies the observations in the NC dataset so you can merge. Similarly for the SC dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to merge the NC+SC with the NC dataset by whatever the key variable is.&lt;/P&gt;
&lt;P&gt;Then merge the result with the SC dataset by whatever the key variable is for that merge.&amp;nbsp; Note that you need re-sort the intermediate result first if you are using data step merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take care that the variables are you are trying to add from the NC and SC dataset do not use the same names.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 16:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Data-with-Replacement/m-p/727917#M226472</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-20T16:28:47Z</dc:date>
    </item>
  </channel>
</rss>

