<?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: Match Merge not lining up in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723975#M224743</link>
    <description>&lt;P&gt;Hey Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the reply, I updated the program to include a "merge variable" in each data set, but the merge is still not lining up as I am expecting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA1 &lt;SPAN&gt;"10130147190001" &lt;/SPAN&gt;:
merge_var = SUBSTR(STRIP(account), 1, 10) ;  &amp;lt;-- "&lt;SPAN&gt;1013014719"&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA2 "10010130147190001" :
merge_var = SUBSTR(STRIP(accountnumber), 4, 10) ;  &amp;lt;-- "1013014719"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA3 "1013014719" :
merge_var = STRIP(acctid) ;  &amp;lt;-- "1013014719"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I will have to use PROC SQL for this then?&amp;nbsp; :'(&lt;/P&gt;</description>
    <pubDate>Fri, 05 Mar 2021 19:37:08 GMT</pubDate>
    <dc:creator>GBL__</dc:creator>
    <dc:date>2021-03-05T19:37:08Z</dc:date>
    <item>
      <title>Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723932#M224731</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to merge three files together using the 'account' variable from the first data set:&lt;/P&gt;
&lt;P&gt;i.e. "10130147190001"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the second data set has an 'accountnumber' variable, but in this data set it includes additional info:&lt;/P&gt;
&lt;P&gt;i.e. "10010130147190001"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the third data set has an 'acctid' variable, but in this data set it is excluding info at the end:&lt;/P&gt;
&lt;P&gt;i.e. "1013014719"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in the second and third data set I am creating the 'account' variable to use to merge on:&lt;/P&gt;
&lt;PRE&gt;account =&amp;nbsp;SUBSTR(STRIP(accountnumber), 4) ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And&lt;/P&gt;
&lt;PRE&gt;account = CATS(STRIP(acctid), "0001") ;&lt;/PRE&gt;
&lt;P&gt;Each 'account' variable is defined in the LENGTH statement for each data set when importing as Character with length of 30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when merging these three variables do NOT align in the final merged data set&lt;/P&gt;
&lt;PRE&gt;PROC SORT DATA=data1 ;
  BY account ;
RUN ;

PROC SORT DATA=data2 ;
  BY account ;
RUN ;

DATA merged1 ;
  MERGE data1 data2 ;
  BY account ;
RUN ;

PROC SORT DATA=merged1 ;
  BY account ;
RUN ;

PROC SORT DATA=data3 ;
  BY account ;
RUN ;

DATA final_merged ;
  MERGE merged1 data3 ;
  BY account ;
RUN ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: There were 9379 observations read from the data set WORK.DATA1.
NOTE: SAS sort was used.
NOTE: The data set WORK.DATA1 has 9379 observations and 46 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.04 seconds
      user cpu time       0.03 seconds
      system cpu time     0.01 seconds
      memory              7061.37k
      OS Memory           28328.00k
      Timestamp           03/05/2021 11:29:13 AM
      Step Count                        160  Switch Count  45&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 767 observations read from the data set WORK.DATA2.&lt;BR /&gt;NOTE: SAS sort was used.&lt;BR /&gt;NOTE: The data set WORK.DATA2 has 767 observations and 54 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;      real time 0.03 seconds&lt;BR /&gt;      user cpu time 0.01 seconds&lt;BR /&gt;      system cpu time 0.01 seconds&lt;BR /&gt;      memory 1905.25k&lt;BR /&gt;      OS Memory 23188.00k&lt;BR /&gt;      Timestamp 03/05/2021 11:29:13 AM&lt;BR /&gt;      Step Count 161 Switch Count 41&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 9379 observations read from the data set WORK.DATA1.&lt;BR /&gt;NOTE: There were 767 observations read from the data set WORK.DATA2.&lt;BR /&gt;NOTE: The data set WORK.MERGED1 has 10146 observations and 99 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;      real time 0.07 seconds&lt;BR /&gt;      user cpu time 0.01 seconds&lt;BR /&gt;      system cpu time 0.06 seconds&lt;BR /&gt;      memory 1258.34k&lt;BR /&gt;      OS Memory 22156.00k&lt;BR /&gt;      Timestamp 03/05/2021 11:29:13 AM&lt;BR /&gt;      Step Count 162 Switch Count 43&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 10146 observations read from the data set WORK.MERGED1.&lt;BR /&gt;NOTE: SAS sort was used.&lt;BR /&gt;NOTE: The data set WORK.MERGED1 has 10146 observations and 99 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;      real time 0.07 seconds&lt;BR /&gt;      user cpu time 0.01 seconds&lt;BR /&gt;      system cpu time 0.06 seconds&lt;BR /&gt;      memory 15542.37k&lt;BR /&gt;      OS Memory 37072.00k&lt;BR /&gt;      Timestamp 03/05/2021 11:29:13 AM&lt;BR /&gt;      Step Count 163 Switch Count 45&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 185 observations read from the data set WORK.DATA3.&lt;BR /&gt;NOTE: SAS sort was used.&lt;BR /&gt;NOTE: The data set WORK.DATA3 has 185 observations and 41 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;      real time 0.03 seconds&lt;BR /&gt;      user cpu time 0.00 seconds&lt;BR /&gt;      system cpu time 0.03 seconds&lt;BR /&gt;      memory 810.18k&lt;BR /&gt;      OS Memory 22156.00k&lt;BR /&gt;      Timestamp 03/05/2021 11:29:13 AM&lt;BR /&gt;      Step Count 164 Switch Count 41&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 10146 observations read from the data set WORK.MERGED1.&lt;BR /&gt;NOTE: There were 185 observations read from the data set WORK.DATA3.&lt;BR /&gt;NOTE: The data set WORK.FINAL_MERGED has 10331 observations and 139 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;      real time 0.08 seconds&lt;BR /&gt;      user cpu time 0.03 seconds&lt;BR /&gt;      system cpu time 0.04 seconds&lt;BR /&gt;      memory 1520.84k&lt;BR /&gt;      OS Memory 22464.00k&lt;BR /&gt;      Timestamp 03/05/2021 11:29:14 AM&lt;BR /&gt;      Step Count 165 Switch Count 43&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NOT MATCH MERGING.JPG" style="width: 475px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55499i1DF96820E30CA1A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="NOT MATCH MERGING.JPG" alt="NOT MATCH MERGING.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each of these three account variables are the same type and length.&amp;nbsp; I have tried COMPRESS(), STRIP() etc., I know I am an idiot, but what am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 18:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723932#M224731</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2021-03-05T18:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723951#M224734</link>
      <description>&lt;P&gt;If the first 10 characters are unique, use SUBSTR with 1,10 on the longer strings.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 18:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723951#M224734</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-05T18:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723975#M224743</link>
      <description>&lt;P&gt;Hey Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the reply, I updated the program to include a "merge variable" in each data set, but the merge is still not lining up as I am expecting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA1 &lt;SPAN&gt;"10130147190001" &lt;/SPAN&gt;:
merge_var = SUBSTR(STRIP(account), 1, 10) ;  &amp;lt;-- "&lt;SPAN&gt;1013014719"&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA2 "10010130147190001" :
merge_var = SUBSTR(STRIP(accountnumber), 4, 10) ;  &amp;lt;-- "1013014719"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;In DATA3 "1013014719" :
merge_var = STRIP(acctid) ;  &amp;lt;-- "1013014719"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I will have to use PROC SQL for this then?&amp;nbsp; :'(&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 19:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/723975#M224743</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2021-03-05T19:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724016#M224755</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268542"&gt;@GBL__&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your screenshot shows a portion of dataset &lt;FONT face="courier new,courier"&gt;final_merged&lt;/FONT&gt;, I suspect that invisible characters (such as tabs, '09'x) have hampered the match merge. To check this assumption I would display the seemingly equal values in $HEX60. format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=final_merged(firstobs=... obs=...);
column account=acchex account;
define acchex / format=$hex60.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use suitable observation numbers (in the &lt;FONT face="courier new,courier"&gt;firstobs=&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;obs=&lt;/FONT&gt; dataset options) so that the observations from the screenshot are included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result might look like this (without highlighting, though):&lt;/P&gt;
&lt;PRE&gt;  account                                                       account
  3130313330313437313630303031&lt;FONT color="#FF0000"&gt;09&lt;/FONT&gt;202020202020202020202020202020  10130147160001
  313031333031343731363030303120202020202020202020202020202020  10130147160001&lt;/PRE&gt;
&lt;P&gt;Then you would&amp;nbsp;&lt;EM&gt;know&lt;/EM&gt; the culprit (here: trailing tab character in the first observation). The COMPRESS function can remove all sorts of unwanted characters and just &lt;STRONG&gt;k&lt;/STRONG&gt;eep &lt;STRONG&gt;d&lt;/STRONG&gt;igits:&lt;/P&gt;
&lt;PRE&gt;&lt;EM&gt;cleanacc&lt;/EM&gt;=compress(&lt;EM&gt;dirtyacc&lt;/EM&gt;,,'&lt;STRONG&gt;kd&lt;/STRONG&gt;');&lt;/PRE&gt;
&lt;P&gt;This would be applied to the relevant variables in the process of creating the &lt;FONT face="courier new,courier"&gt;account&lt;/FONT&gt; variables (and, if necessary, to &lt;FONT face="courier new,courier"&gt;account&lt;/FONT&gt; from the first dataset as well) before the sort and merge steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 20:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724016#M224755</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-05T20:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724023#M224759</link>
      <description>&lt;P&gt;I think this is what you are looking for.&lt;BR /&gt;Basically get your account numbers into the same format, then do a SQL merge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Create Sample Data */
data table1 ;
	do i = 1 to 10 ;
		account=putn(i,"z5.")!!"aaa" ;
		output ;
	end ;
run ;

data table2 ;
	do i = 1 to 10 by 2;
		accountNumber="bbb"!!putn(i,"z5.")!!"aaa" ;
		output ;
	end ;
run ;

data table3 ;
	do i = 1 to 10 by 3;
		acctid=putn(i,"z5.") ;
		output ;
	end ;
run ;

/* Standardize account numbers to acctId format on table3 */
data table1Std ;
	set table1 ;
	matchId=substr(account,1,5) ;
run ;

data table2Std ;
	set table2 ;
	matchId=substr(accountNumber,4,5) ;
run ;

/* Merge the tables */
proc sql ;
	create table merged as
	select table1Std.account, table2Std.accountNumber, table3.acctId
	from
		table1Std, table2Std, table3
	where
		table1Std.matchId=table2Std.matchid=table3.acctId
	;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Mar 2021 20:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724023#M224759</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-03-05T20:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724027#M224761</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for the reply!&amp;nbsp; I did try this earlier before creating this post (searched for awhile).&amp;nbsp; And using your recommendation here is some output (though not the exact same from the screenshot, but still):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HEX_ACCOUNT.JPG" style="width: 676px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55527iC62DE8E4788B5F24/image-size/large?v=v2&amp;amp;px=999" role="button" title="HEX_ACCOUNT.JPG" alt="HEX_ACCOUNT.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didnt notice any "bad" characters earlier, or just now when I ran the above&amp;nbsp; :'(&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 20:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724027#M224761</guid>
      <dc:creator>GBL__</dc:creator>
      <dc:date>2021-03-05T20:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merge not lining up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724040#M224766</link>
      <description>&lt;P&gt;Thanks for checking. The "HEX ACCOUNT" covers only 20 of the 30 characters in &lt;FONT face="courier new,courier"&gt;account&lt;/FONT&gt;, so there's a remote possibility of differences in the remaining characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If nothing suspicious was found there, I would probably create small subsets (with only a few relevant observations and variables) of the datasets to be merged and run the MERGE step on these samples in a new SAS session.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 21:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merge-not-lining-up/m-p/724040#M224766</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-05T21:06:36Z</dc:date>
    </item>
  </channel>
</rss>

