<?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: Multiple merge in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13361#M1939</link>
    <description>thats fantastic, thank you so much.&lt;BR /&gt;
&lt;BR /&gt;
i'm not too familiar with creating tables in sql, how would I change the code so that for anyone mnissing a 'weight' (did not match to the lookup table) I would set their weight value to a 1?&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
    <pubDate>Wed, 15 Jun 2011 12:33:35 GMT</pubDate>
    <dc:creator>Danglytics</dc:creator>
    <dc:date>2011-06-15T12:33:35Z</dc:date>
    <item>
      <title>Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13356#M1934</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
My main dataset of customers contains a variable FSALDU, 6 characters of postalcodes across canada.&lt;BR /&gt;
for example:&lt;BR /&gt;
id fsaldu&lt;BR /&gt;
1 M5G2H5&lt;BR /&gt;
2 M5V3S2&lt;BR /&gt;
3 L8R0L9&lt;BR /&gt;
&lt;BR /&gt;
I have a lookup/reference file with FSALDU, but its a mix of FSA (3chars) and FSALDU (6char) and weights.&lt;BR /&gt;
for example: &lt;BR /&gt;
FSALDU weight&lt;BR /&gt;
M5G 1&lt;BR /&gt;
M5V3E9 1&lt;BR /&gt;
L5R 0.89&lt;BR /&gt;
L5S 0.67&lt;BR /&gt;
T5R1R3 0.92&lt;BR /&gt;
T5R1S2 0.54&lt;BR /&gt;
etc..&lt;BR /&gt;
&lt;BR /&gt;
I want to first merge my main dataset by the full fsaldu, then for anyone who did NOT match the full fsaldu, I want to merge on their FSA.&lt;BR /&gt;
I have no problem merging on the FSALDU, but not quite sure how I can do the second step.&lt;BR /&gt;
Thanks in advance for your help.</description>
      <pubDate>Tue, 14 Jun 2011 15:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13356#M1934</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2011-06-14T15:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13357#M1935</link>
      <description>Easiest method is to create a new variable, FSA and merge on that. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Another way is to use proc SQL and an update statement (untested).&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
update have h&lt;BR /&gt;
set weight=(select weight from fsaldu as f &lt;BR /&gt;
where substr(h.fsaldu, 1,3)=f.fsaldu and h.weight=.);&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 14 Jun 2011 16:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13357#M1935</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-06-14T16:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13358#M1936</link>
      <description>im still stuck with this..&lt;BR /&gt;
&lt;BR /&gt;
if my weight table looks like this:&lt;BR /&gt;
fsaldu weight&lt;BR /&gt;
K0A 1&lt;BR /&gt;
K0A3K0 0.69&lt;BR /&gt;
K0A3NO 0.74&lt;BR /&gt;
&lt;BR /&gt;
and my customer table:&lt;BR /&gt;
id fsaldu &lt;BR /&gt;
1 K0A3K0&lt;BR /&gt;
2 K0A8PN&lt;BR /&gt;
3 K0A3N0&lt;BR /&gt;
4 K0A8T6 &lt;BR /&gt;
&lt;BR /&gt;
how can i get to the final table looking like&lt;BR /&gt;
id fsaldu weight&lt;BR /&gt;
1 K0A3K0 0.69&lt;BR /&gt;
2 K0A8PN 1&lt;BR /&gt;
3 K0A3N0 0.74&lt;BR /&gt;
4 K0A8T6  1&lt;BR /&gt;
&lt;BR /&gt;
Thanks

Message was edited by: Danglytics</description>
      <pubDate>Tue, 14 Jun 2011 17:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13358#M1936</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2011-06-14T17:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13359#M1937</link>
      <description>Use DATA step with MATCH merge on you FSALDU variable.  Then for any no-match conditions, you will then need to create your FSA variable as you have described in with SUBSTR in an assignment statement for positions 1-3, and do another DATA step match-merge with a MERGE / BY statement on FSA.&lt;BR /&gt;
&lt;BR /&gt;
It's quite possible, as well, with PROC SQL.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 14 Jun 2011 18:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13359#M1937</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-14T18:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13360#M1938</link>
      <description>There's a typo in your postal code list...&lt;BR /&gt;
&lt;BR /&gt;
but this is what you can do using proc sql&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have1;&lt;BR /&gt;
input id postal $;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 K0A3K0&lt;BR /&gt;
2 K0A8PN&lt;BR /&gt;
3 K0A3N0&lt;BR /&gt;
4 K0A8T6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
input postal $ weight;&lt;BR /&gt;
cards;&lt;BR /&gt;
K0A 1&lt;BR /&gt;
K0A3K0 0.69&lt;BR /&gt;
K0A3N0 0.74&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table want as&lt;BR /&gt;
	select h1.id, h1.postal, h2.weight as weight1, h2_s.weight as weight2, case when h2.weight=. then h2_s.weight else h2.weight end as weight&lt;BR /&gt;
	from have1 as h1&lt;BR /&gt;
	left join have2 as h2&lt;BR /&gt;
	on h1.postal=h2.postal&lt;BR /&gt;
	left join have2 as h2_s&lt;BR /&gt;
	on substr(compress(h1.postal), 1,3)=compress(h2_s.postal)&lt;BR /&gt;
	order by id;&lt;BR /&gt;
quit; &lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 14 Jun 2011 19:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13360#M1938</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-06-14T19:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13361#M1939</link>
      <description>thats fantastic, thank you so much.&lt;BR /&gt;
&lt;BR /&gt;
i'm not too familiar with creating tables in sql, how would I change the code so that for anyone mnissing a 'weight' (did not match to the lookup table) I would set their weight value to a 1?&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Wed, 15 Jun 2011 12:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13361#M1939</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2011-06-15T12:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13362#M1940</link>
      <description>The first left join, joins the tables together based on the full id and weight from this is stored in variable weight1.&lt;BR /&gt;
The second left join joins the tables together based on the FSA and the weight from this is stored in the variable weight2&lt;BR /&gt;
&lt;BR /&gt;
The case statement is almost the equivalent of a if then else or a select statement.&lt;BR /&gt;
&lt;BR /&gt;
See here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473682.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473682.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
so right now it checks for a missing value in weight1, if so then assigns the weight2 value.  &lt;BR /&gt;
You can add in a line to the case statement that checks for missing both and then set it to 1.  &lt;BR /&gt;
&lt;BR /&gt;
If you can't figure it out, post your code and I'll help to debug it. &lt;BR /&gt;
&lt;BR /&gt;
HTH</description>
      <pubDate>Wed, 15 Jun 2011 15:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13362#M1940</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-06-15T15:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13363#M1941</link>
      <description>The COALESCE function makes things somewhat more concise.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table want as&lt;BR /&gt;
	select have1.*, coalesce (h2.weight, h2_s.weight, 1) as weight&lt;BR /&gt;
	from have1 as h1&lt;BR /&gt;
	left join have2 as h2&lt;BR /&gt;
	on h1.postal=h2.postal&lt;BR /&gt;
	left join have2 as h2_s&lt;BR /&gt;
	on substr(h1.postal,1,3)=h2_s.postal&lt;BR /&gt;
	order by id;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Notice that I got rid of the alias for HAVE1 as well as the COMPRESS calls. I saw no need for them.&lt;BR /&gt;
&lt;BR /&gt;
Also, better test data:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have1;&lt;BR /&gt;
input id postal $;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 K0A3K0&lt;BR /&gt;
2 K0A8PN&lt;BR /&gt;
3 K0A3N0&lt;BR /&gt;
4 K0A8T6&lt;BR /&gt;
5 XXXXXX&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
input postal $ weight;&lt;BR /&gt;
cards;&lt;BR /&gt;
K0A 0.987&lt;BR /&gt;
K0A3K0 0.69&lt;BR /&gt;
K0A3N0 0.74&lt;BR /&gt;
;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; thats fantastic, thank you so much.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; i'm not too familiar with creating tables in sql, how&lt;BR /&gt;
&amp;gt; would I change the code so that for anyone mnissing a&lt;BR /&gt;
&amp;gt; 'weight' (did not match to the lookup table) I would&lt;BR /&gt;
&amp;gt; set their weight value to a 1?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks.</description>
      <pubDate>Wed, 15 Jun 2011 16:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13363#M1941</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-06-15T16:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13364#M1942</link>
      <description>proc sql;	&lt;BR /&gt;
create table want as	&lt;BR /&gt;
select h1.id&lt;BR /&gt;
, h1.postal&lt;BR /&gt;
, h2.weight as weight1&lt;BR /&gt;
, h2_s.weight as weight2, &lt;BR /&gt;
&lt;BR /&gt;
case when h2.weight=. then h2_s.weight &lt;BR /&gt;
else h2.weight&lt;BR /&gt;
else h2.weight=. and h2_s.weight =. then weight=1&lt;BR /&gt;
end as weight&lt;BR /&gt;
&lt;BR /&gt;
from have1 as h1 left join have2 as h2&lt;BR /&gt;
on h1.postal=h2.postal left join have2 as h2_s&lt;BR /&gt;
on substr(compress(h1.postal), 1,3)=compress(h2_s.postal)&lt;BR /&gt;
order by id;&lt;BR /&gt;
&lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
this isnt quite working for me</description>
      <pubDate>Wed, 15 Jun 2011 16:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13364#M1942</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2011-06-15T16:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13365#M1943</link>
      <description>Thanks all for your help, problem solved!</description>
      <pubDate>Wed, 15 Jun 2011 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13365#M1943</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2011-06-15T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple merge</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13366#M1944</link>
      <description>Just another way, Can not suppress impulse to code it .:)&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have1;&lt;BR /&gt;
input id postal $;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 K0A3K0&lt;BR /&gt;
2 K0A8PN&lt;BR /&gt;
3 K0A3N0&lt;BR /&gt;
4 K0A8T6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
input postal $ weight;&lt;BR /&gt;
cards;&lt;BR /&gt;
K0A 1&lt;BR /&gt;
K0A3K0 0.69&lt;BR /&gt;
K0A3N0 0.74&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(drop=_postal);&lt;BR /&gt;
 set have1;&lt;BR /&gt;
 do i=1 to _nobs;&lt;BR /&gt;
  set have2(rename=(postal=_postal)) point=i nobs=_nobs;&lt;BR /&gt;
  if postal=_postal then do;output; leave; end;&lt;BR /&gt;
  if i=_nobs then do;&lt;BR /&gt;
           do j=1 to __nobs;&lt;BR /&gt;
            set have2(rename=(postal=_postal)) point=j nobs=__nobs;&lt;BR /&gt;
            if postal eq: strip(_postal) then do;output; leave;end;&lt;BR /&gt;
           end;&lt;BR /&gt;
                 end;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 16 Jun 2011 06:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-merge/m-p/13366#M1944</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-06-16T06:07:19Z</dc:date>
    </item>
  </channel>
</rss>

