<?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: Problem to merge two dataset 1:1 merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831778#M328741</link>
    <description>&lt;P&gt;Questions like these are always easier if we can see/use some sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is&amp;nbsp;ami_weeks_ind uniqye by&amp;nbsp;lopenummer, index, uke ?&lt;/P&gt;</description>
    <pubDate>Mon, 05 Sep 2022 08:54:54 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-09-05T08:54:54Z</dc:date>
    <item>
      <title>Problem to merge two dataset 1:1 merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831773#M328739</link>
      <description>&lt;P&gt;I have problem to merge something in SAS. I have this dataset in SAS:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;data ami_aggregert; 
set ami_aggr; 
tjenester _NPR = tjenestebruk_Sum; 
label lopenummer uke tjeneste_NPR index; 
run; 

* then i sort; 

proc sort data=ami_aggregert; by lopenummer index uke; run; 
proc sort data=ami_weeks_ind; by lopenummer index uke; run; 


data ami_weeks_full_NPR; 
merge ami_aggregert (in=a) ami_weeks_ind (in=b) ; 
if a and b; 
by lopenummer index uke; 
run; &lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="user40_0-1662367147156.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74984iB1FB759B9DC71AD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="user40_0-1662367147156.png" alt="user40_0-1662367147156.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first dataset ami_aggregert contains 11 rows and if I merge it with 52 weeks of within each index, then I got 16 rows. I don't understand that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Must i sort it on another way?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 08:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831773#M328739</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-09-05T08:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to merge two dataset 1:1 merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831778#M328741</link>
      <description>&lt;P&gt;Questions like these are always easier if we can see/use some sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is&amp;nbsp;ami_weeks_ind uniqye by&amp;nbsp;lopenummer, index, uke ?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 08:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831778#M328741</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-05T08:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to merge two dataset 1:1 merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831780#M328743</link>
      <description>Yes, it is uniwuq bye lopenummer , uke and index. one example . The aggregate dataset is for example like this:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;lopenummer index uke ant_tjenester&lt;BR /&gt;101 , 1 , 1, 2,&lt;BR /&gt;101 , 1, 1, 3,&lt;BR /&gt;101, 2, 4, 5,&lt;BR /&gt;102, 1, 2, 2,&lt;BR /&gt;102, 1, 2, 1,&lt;BR /&gt;102, 2, 1, 1,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This should be coded to another dataset that contains lopenummer, index - number and week number,&lt;BR /&gt;&lt;BR /&gt;You got this?</description>
      <pubDate>Mon, 05 Sep 2022 09:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831780#M328743</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-09-05T09:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to merge two dataset 1:1 merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831813#M328765</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432803"&gt;@user40&lt;/a&gt;&amp;nbsp;To minimize the guesswork for us and also to allow us to spend our time on answering your question with tested code what would help is:&lt;/P&gt;
&lt;P&gt;1. Post sample data via a fully working and tested SAS data step (the have data)&lt;/P&gt;
&lt;P&gt;2. Post the desired result (either another SAS data step creating the want data or then in some other way)&lt;/P&gt;
&lt;P&gt;3. Describe the logic to get from have to want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By sharing the want data based on the have data it's much easier for us to interpret your description of the logic as it's often really hard to formulate such logic unambiguously.&lt;/P&gt;
&lt;P&gt;Also: It requires a bit more prep work on your end but if you provide such information upfront you will get most of the time rather quickly the answer you need.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 14:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831813#M328765</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-05T14:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem to merge two dataset 1:1 merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831855#M328786</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;The first dataset ami_aggregert contains 11 rows and if I merge it with 52 weeks of within each index, then I got 16 rows. I don't understand that?&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you are restricting the results to observations that have contributions from both inputs you should only get 11 observations if the key variables uniquely identify observations in both datasets.&amp;nbsp; The fact that instead you got 16 means that the extra 5 observations represent those that have repeated observations in one (or both) of the two input datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are they key variables that uniquely identify the observations in the first dataset?&lt;/P&gt;
&lt;P&gt;What are the key variables that uniquely identify the observations in the second dataset?&lt;/P&gt;
&lt;P&gt;What are the variables that you want to combine on?&amp;nbsp; What do you want to do if there are repeated observations for those variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 19:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-to-merge-two-dataset-1-1-merge/m-p/831855#M328786</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-05T19:41:20Z</dc:date>
    </item>
  </channel>
</rss>

