<?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: Issue with data merge, losing information from one dataset that I needed in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749995#M235821</link>
    <description>If both were numbers that wouldn't matter and formats don't affect merging. &lt;BR /&gt;And the log would have had errors if that was the case as well. &lt;BR /&gt;&lt;BR /&gt;Please post the proc contents from the data sets you're trying to merge.&lt;BR /&gt;</description>
    <pubDate>Wed, 23 Jun 2021 20:10:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-06-23T20:10:24Z</dc:date>
    <item>
      <title>Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749971#M235802</link>
      <description>&lt;P&gt;Hello, I am having trouble with merging two dataset of unequal sample sizes but need to retain all variables of both datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset a: N=1,500 and number of variables = 450&lt;/P&gt;&lt;P&gt;dataset b: N=150,000 and number of variables = 8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Do a one to one merge by a variable (VAR1)&lt;/LI&gt;&lt;LI&gt;I want all the information in dataset b (VAR2-VAR8) to merge with dataset a (Final N=1,500)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;proc sort data=a;&lt;BR /&gt;by VAR1; run;&lt;BR /&gt;proc sort data=b;&lt;BR /&gt;by VAR1; run;&lt;/P&gt;&lt;P&gt;data final_data;&lt;BR /&gt;merge a(in=a) b;&lt;BR /&gt;if a;&lt;BR /&gt;by VAR1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Even though I was able to get the right N (1,500), my final dataset has VAR2-VAR8 variables missing from dataset b.&lt;BR /&gt;Is there a way to avoid this error? I need that information in my final dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;VAR1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR4&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR5&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR6&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR8&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;101&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&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t;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;141&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;169&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749971#M235802</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T19:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749975#M235805</link>
      <description>I'm guessing the BY variable VALUES in A and B are different even though they may LOOK the same.  Perhaps leading spaces if character.  Also I usually put the sub-setting IF after the BY but I don't' think that is the problem.</description>
      <pubDate>Wed, 23 Jun 2021 19:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749975#M235805</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-06-23T19:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749977#M235806</link>
      <description>&lt;P&gt;Is this referring to formatting, etc.? VAR1 in both dataset A and B are the same (Numerical, length=8, format z5.).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749977#M235806</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T19:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749984#M235812</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332852"&gt;@lindst801&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is this referring to formatting, etc.? VAR1 in both dataset A and B are the same (Numerical, length=8, format z5.).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. It is the values of Var1. If there are no values that actually match then the added variables appear but since no matches occur they are missing.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data a;
   input var1 varb varc;
datalines;
1  1 2 3 
2  2 4 6
;

data b;
   input var1 var2 var3;
datalines;
22  1 2 3
33  4 6 8
;
run;

data example1;
  merge a (in=a)  b;
  if a;
  by var1;
run;&lt;/PRE&gt;
&lt;P&gt;This example is small enough that you can tell by eye that no Var1 values are the same in both sets.&lt;/P&gt;
&lt;P&gt;Remove the "if a;" to see a different result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749984#M235812</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-23T20:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749985#M235813</link>
      <description>&lt;P&gt;If you are using the Z5. format to display the numbers and they are not actually integers then they will LOOK the same, whether or not they are the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try rounding the value to integers and see if that changes anything.&amp;nbsp; Use the ROUND() function with 1 for the second argument.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749985#M235813</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-23T19:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749988#M235815</link>
      <description>&lt;P&gt;That is not how the dataset I am working with is set up. This is a case where it is the actual following (pulling from your example)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data a;
   input var1 varb varc;
datalines;
1  1 2 3 
2  2 4 6
;

data b;
   input var1 var2 var3;
datalines;
2  1 2 3
3  4 6 8
;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The final result from the program that they values did match (VAR1), the issue is that the reminder of the dataset b data is missing (VAR2-VAR8 is missing).&lt;/P&gt;&lt;P&gt;Once I had removed 'if a', not only do I not get matches (I do not get a final desired n of 1,500 but instead 150,000) but VAR2-VAR8 is set to missing as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749988#M235815</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T19:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749990#M235816</link>
      <description>&lt;P&gt;Rather than hypotheticals, if you can show your full code and log that would be easier. Are there any warnings or notes in the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the values to be empty it means one of two things is happening:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;There is no match found in the other table so they get assigned empty&lt;/LI&gt;
&lt;LI&gt;The match is found on VAR1 but all the variables in the data set are empty for some reason (data collection issues?)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;It's usually a variant on 1, where the data won't match because one is&amp;nbsp; "A" versus "a", where the case is different.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know you say&amp;nbsp; you have numeric but given what you've stated these are the likely possibilities.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, you could have not told us something that is affecting the results - therefore the request for the actual code and log to help diagnose the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332852"&gt;@lindst801&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That is not how the dataset I am working with is set up. This is a case where it is the actual following (pulling from your example)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a;
   input var1 varb varc;
datalines;
1  1 2 3 
2  2 4 6
;

data b;
   input var1 var2 var3;
datalines;
2  1 2 3
3  4 6 8
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The final result from the program that they values did match (VAR1), the issue is that the reminder of the dataset b data is missing (VAR2-VAR8 is missing).&lt;/P&gt;
&lt;P&gt;Once I had removed 'if a', not only do I not get matches (I do not get a final desired n of 1,500 but instead 150,000) but VAR2-VAR8 is set to missing as well.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749990#M235816</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-23T20:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749992#M235818</link>
      <description>&lt;P&gt;I have to use the z5. format to have padding for dataset A (Example, dataset A originally had '4056' when it should be '04056').&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since the information in VAR1 are already integers (ZIP codes), I am not sure rounding to an integer value would help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749992#M235818</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T20:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749995#M235821</link>
      <description>If both were numbers that wouldn't matter and formats don't affect merging. &lt;BR /&gt;And the log would have had errors if that was the case as well. &lt;BR /&gt;&lt;BR /&gt;Please post the proc contents from the data sets you're trying to merge.&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/749995#M235821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-23T20:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750004#M235829</link>
      <description>&lt;P&gt;If the values are ZIP codes then you should be storing them as strings not numbers.&amp;nbsp; There is no meaning to the mean of a zip code.&amp;nbsp; If someone has mistakenly stored them as a number you can use the Z format with the PUT() function to generate a new variable with the strings that include leading zeros.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you did let SAS autoconvert numbers into strings, for example with code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length new_var $20;
new_var=old_var;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then SAS will right align the digit string it generates to store into the character variable.&lt;/P&gt;
&lt;PRE&gt;477   data test;
478     x=1234;
479     length y $20;
480     y=x;
481     len=length(y);
482     put x= y=:$quote. len=;
483   run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      480:5
x=1234 y="                1234" len=20
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check how many matches there are between your datasets to get a better sense of what your issue is.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count(*) as nobs
     , count(var1) as n_nonmissing
     , count(distinct var1) as n_values
from A
;
select count(*) as nobs
     , count(var1) as n_nonmissing
     , count(distinct var1) as n_values
from B
;
select count(*) as nobs
     , count(var1) as n_nonmissing
     , count(distinct var1) as n_values
from B
where VAR1 in (select var1 from A)
;
select count(*) as nobs
     , count(var1) as n_nonmissing
     , count(distinct var1) as n_values
from A
where VAR1 in (select var1 from B)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750004#M235829</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-23T20:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750007#M235832</link>
      <description>&lt;P&gt;Unfortunately, there has been no documentation in my log that there was an error. I only was able to find out that it was an error by conducting a proc print check.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is further information from PROC CONTENTS I can provide:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Data set name&lt;/P&gt;&lt;/TD&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t;P&gt;Data Representation&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;----------&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Encoding&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;--------&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sort information&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sortedby&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;VAR1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Validated&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;YES&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Character Set&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ANSI&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750007#M235832</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T20:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750013#M235835</link>
      <description>You need to provide the format type and label information for VAR1 in each data set as well. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750013#M235835</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-23T20:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750014#M235836</link>
      <description>Or work with Tech Support (if you have a paid license) as they can take and handle private data, anything posted here is public.</description>
      <pubDate>Wed, 23 Jun 2021 20:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750014#M235836</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-23T20:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750015#M235837</link>
      <description>&lt;P&gt;This was very helpful, but my final concern is handling ZIP code information where there are leading zeros. How would you modify the code to ensure that the leading zeros are in place?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750015#M235837</guid>
      <dc:creator>lindst801</dc:creator>
      <dc:date>2021-06-23T20:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750017#M235839</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332852"&gt;@lindst801&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That is not how the dataset I am working with is set up. This is a case where it is the actual following (pulling from your example)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a;
   input var1 varb varc;
datalines;
1  1 2 3 
2  2 4 6
;

data b;
   input var1 var2 var3;
datalines;
2  1 2 3
3  4 6 8
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;The final result from the program that they values did match (VAR1), the issue is that the reminder of the dataset b data is missing (VAR2-VAR8 is missing).&lt;/P&gt;
&lt;P&gt;Once I had removed 'if a', not only do I not get matches (I do not get a final desired n of 1,500 but instead 150,000) but VAR2-VAR8 is set to missing as well.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have shown exactly 0 records of your actual data.&lt;/P&gt;
&lt;P&gt;I will bet a short stack of $$$ that your data actual values do not match.&lt;/P&gt;
&lt;P&gt;Or that var2-var8 are missing on the ones that do match. If the same variables appear in both sets the values in B would overwrite the ones from A. See this example:&lt;/P&gt;
&lt;PRE&gt;data a;
   input var1 var2 var3;
datalines;
1  1 2 3 
2  2 4 6
;

data b;
   input var1 var2 var3;
datalines;
1 . . .
2 . . . 
;
run;

data example2;
   merge a (in=a) b;
   if a;
   by var1;
run;&lt;/PRE&gt;
&lt;P&gt;Here I have forced B to have missing values. Then on the matching records in A those missing values REPLACE the values in A.&lt;/P&gt;
&lt;P&gt;Note that the order of the data sets on the Merge statement controls this behavior. Consider:&lt;/P&gt;
&lt;PRE&gt;data example3;
   merge b  a (in=a);
   if a;
   by var1;
run;&lt;/PRE&gt;
&lt;P&gt;So items to consider: Which variables are in which sets, order of merge, actual values of the BY variables.&lt;/P&gt;
&lt;P&gt;Which is why Proc contents information was requested.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750017#M235839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-23T20:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750024#M235842</link>
      <description>&lt;P&gt;Store it as character from the beginning is the best bet.&amp;nbsp; If you are reading data from a text file make sure to read the value as character.&amp;nbsp; In particular do not let PROC IMPORT or Excel guess how to define the variable, because then it will become numeric.&amp;nbsp; Which will not work once you have ZIP+4 values or values of postal codes from other countries.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a numeric variable then the leading zeros do not matter.&amp;nbsp; 100, 0100 and 00100 are all the same number.&lt;/P&gt;
&lt;P&gt;If you want to create a character value from a numeric value use the PUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;zipcode = put(zip_number,z5.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have a character value and some are missing the leading zero then a quick method is to convert the string to a number and then use PUT().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;zipcode = put(input(strip(zipcode),32.),z5.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750024#M235842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-23T20:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with data merge, losing information from one dataset that I needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750026#M235843</link>
      <description>&lt;P&gt;This is key observation.&lt;/P&gt;
&lt;P&gt;Are you doing a 1-to-many or many-to-many merge?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does either of the dataset have multiple observations per value of VAR1?&amp;nbsp; (If you did the counts I suggested before does the number of observations match the number of distinct values?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When doing a 1 to many match (essentially a lookup) the variables you are adding from the "1" dataset &lt;STRONG&gt;must not exist&lt;/STRONG&gt; in the "many" dataset.&amp;nbsp; Otherwise only the values on the first instance of this by variable group is updated.&amp;nbsp; When the second, third etc observation for that group is read from the "many" dataset then the values read for those variables will overwrite whatever was read from the "1" dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 20:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-data-merge-losing-information-from-one-dataset-that-I/m-p/750026#M235843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-23T20:59:39Z</dc:date>
    </item>
  </channel>
</rss>

