<?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 Problems in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401569#M278751</link>
    <description>&lt;P&gt;If the merge is still not working the way you want, run proc freq on the BY variable for both data sets.&amp;nbsp; Ensure that the values in each data set that should match do in fact match.&amp;nbsp; If they don't transform them in whatever way is necessary to get the desired matches.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2017 00:51:54 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2017-10-06T00:51:54Z</dc:date>
    <item>
      <title>Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401536#M278743</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 datasets that I would like to merge.&lt;/P&gt;&lt;P&gt;dataset1 has 137 observations and 7 variables.&lt;/P&gt;&lt;P&gt;dataset2 has 417 observations and 165 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after sorting both dataset, I put:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data hpvmerge;&lt;/P&gt;&lt;P&gt;merge dataset1 (in=a) dataset2 (in=b);&lt;/P&gt;&lt;P&gt;by study_id;&lt;/P&gt;&lt;P&gt;if a=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS did not give any errors and there was 137 observations and 171 variables in hpvmerge dataset.&lt;/P&gt;&lt;P&gt;however, when I opened this merged dataset, all values for the&amp;nbsp;variables from the larger dataset (dataset2) are missing.&lt;/P&gt;&lt;P&gt;I am not sure what went wrong and would like to get some help from you guys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 22:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401536#M278743</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-05T22:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401542#M278744</link>
      <description>&lt;P&gt;Check to see if study_id has the same values in the two data sets. I think you will find they do not.&lt;/P&gt;
&lt;P&gt;Also, set b2 = b;&amp;nbsp; see if b2 has any nonzero values.&amp;nbsp; b is going to be automatically dropped.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 22:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401542#M278744</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-05T22:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401544#M278745</link>
      <description>&lt;P&gt;With this bit in your code:&lt;/P&gt;
&lt;P&gt;if a=1;&lt;/P&gt;
&lt;P&gt;you only records that have a value for study_id in dataset1. If there are no matching values for study_id&amp;nbsp;in dataset2 then none of the variables would get values from dataset2 but the variables will exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should run proc freq or some other summary on the variable study_id in both sets. Then see if there should be matches. If they aren't matching it may be a matter of 1) no matches or presumptive matches&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;letter case: "Study a" does not match "Study A",&lt;/P&gt;
&lt;P&gt;3) extra characters: "Study&amp;nbsp; A" does not match "Study A" (the first has two spaces)&lt;/P&gt;
&lt;P&gt;4) different characters: "Study_A" does not match "Study A"&lt;/P&gt;
&lt;P&gt;5) the insidious leading blank: " Study A" does not match "Study A"&lt;/P&gt;
&lt;P&gt;If the study id is numeric it there may be a formatting issue such that when you look at them they appear identical but there is an actual difference in the underlying value. 4.3 displayed with an F1 format will look like 4 but not match the actual value 4 in the other set.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 22:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401544#M278745</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-05T22:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401549#M278746</link>
      <description>&lt;P&gt;Than you so much for the suggestion.&lt;/P&gt;&lt;P&gt;So I have ran proc freq on both datasets and there are definitely matching values.&lt;/P&gt;&lt;P&gt;Study id in dataset1 have both numbers only ID and numbers+letters ID, and it is a character variable with a length of 5.&lt;/P&gt;&lt;P&gt;but study id in dataset2&amp;nbsp;have only numbers ID, (numerical variable with length 8, but actually it ranges from only 1 digit to 4 digit ID), so I had to convert to a character variable with a length of $5 before merging.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understood your suggestions correctly,&amp;nbsp;did this&amp;nbsp;cause the missing values in the merged dataset??&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 23:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401549#M278746</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-05T23:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401550#M278747</link>
      <description>&lt;P&gt;Right.&amp;nbsp; If the values do not match, you will not get any observations from&amp;nbsp;dataset2.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 23:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401550#M278747</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-05T23:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401562#M278748</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Can you give some suggestions on how I should fix that?&lt;/P&gt;&lt;P&gt;I can't think of another way of doing this (e.g. convert to character via the put function and make it the same length as dataset1 study ID). I need to keep those IDs with numbers+letters too in dataset1 as I might be linking to a third dataset with this kind of ID format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 00:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401562#M278748</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-06T00:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401567#M278749</link>
      <description>&lt;P&gt;You can keep the original variables, but you must make a variable in each data set that has the same names and values and then merge on it.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 00:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401567#M278749</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-06T00:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401568#M278750</link>
      <description>&lt;P&gt;Sorry I did not make this clear before. The character variable I converted to in dataset2 have the same variable name as study_id in dataset1 (both are named study_id).&amp;nbsp;The original numeric ID variable was named something else.&lt;/P&gt;&lt;P&gt;Should I make a new variable in dataset1 as well and just have the values equal to study_id and link this to dataset2?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 00:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401568#M278750</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-06T00:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401569#M278751</link>
      <description>&lt;P&gt;If the merge is still not working the way you want, run proc freq on the BY variable for both data sets.&amp;nbsp; Ensure that the values in each data set that should match do in fact match.&amp;nbsp; If they don't transform them in whatever way is necessary to get the desired matches.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 00:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401569#M278751</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-06T00:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401572#M278752</link>
      <description>&lt;P&gt;After comparing side by side, I am finally seeing what's wrong:&lt;/P&gt;&lt;P&gt;dataset1 study ID (already a character variable, just picked a few for example)&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;112&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and dataset2 study ID (after converting to character)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;112&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is this happening and how&amp;nbsp;should I fix??&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 01:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401572#M278752</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-06T01:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401575#M278753</link>
      <description>&lt;P&gt;use the left function to left justify in a separate step before the merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x = left(x);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substitute your var name for x.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 01:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401575#M278753</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-06T01:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401577#M278754</link>
      <description>&lt;P&gt;It worked!! Thank you so much I have been trying to figure this out for the whole day!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 01:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401577#M278754</guid>
      <dc:creator>michan22</dc:creator>
      <dc:date>2017-10-06T01:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Problems</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401578#M278755</link>
      <description>&lt;P&gt;Glad I could help!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 01:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Problems/m-p/401578#M278755</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-06T01:23:07Z</dc:date>
    </item>
  </channel>
</rss>

