<?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: Appending 1 dataset into another when they've got different variable order &amp;amp; names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/764094#M241988</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;One can use the CAT function, or manually concatenate TRIMmed values to shorten the string that's hashed.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Aug 2021 03:16:11 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-08-26T03:16:11Z</dc:date>
    <item>
      <title>Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763457#M241790</link>
      <description>&lt;P&gt;I'd appreciate advice on how to best append 1 data set into another when the variables have different names and ordering.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simplified example of 2 data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="372"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="187"&gt;&lt;STRONG&gt;CUSTOMER_SOURCE&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="185"&gt;&lt;STRONG&gt;CUSTOMER_TARGET&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#3366FF"&gt;cust_ident&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#3366FF"&gt;cust_id&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#FF9900"&gt;cust_name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#800000"&gt;cust_adr&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#800000"&gt;cust_address&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF9900"&gt;cust_nm&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They include the same variables, except:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The variables are named differently&lt;/LI&gt;
&lt;LI&gt;The variables are in a different order&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Each day, CUSTOMER_SOURCE will be updated with new rows (via a delta load). All rows should then be appended into CUSTOMER_TARGET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the best way to append data from CUSTOMER_SOURCE into CUSTOMER_TARGET?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 08:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763457#M241790</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2021-08-24T08:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763460#M241793</link>
      <description>&lt;P&gt;You just need to rename the source columns prior to appending to the target table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The one thing you have to think about when appending: Is it possible that you have to re-run your process and if so what should happen so you don't append the same data twice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp; you provide sample data (two fully working data steps creating the master and the transaction table) and then describe exactly the required load then I'm sure someone can help you with a code example how to do this.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 08:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763460#M241793</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-24T08:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763465#M241797</link>
      <description>&lt;P&gt;When using proc append, the order of variables doesn't matter.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 09:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763465#M241797</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-24T09:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763469#M241798</link>
      <description>&lt;P&gt;The syntax you seek is:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc append base=TABLE1 data=TABLE2(rename=&lt;EM&gt;( list of columns to rename&amp;nbsp;&lt;/EM&gt;)); run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The question by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;about appending twice if running the append process twice is very valid. You need to anticipate this case.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 10:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763469#M241798</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-24T10:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763546#M241828</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33000"&gt;@EinarRoed&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'd appreciate advice on how to best append 1 data set into another when the variables have different names and ordering.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simplified example of 2 data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="372"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="187"&gt;&lt;STRONG&gt;CUSTOMER_SOURCE&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="185"&gt;&lt;STRONG&gt;CUSTOMER_TARGET&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#3366FF"&gt;cust_ident&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#3366FF"&gt;cust_id&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#FF9900"&gt;cust_name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#800000"&gt;cust_adr&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT color="#800000"&gt;cust_address&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF9900"&gt;cust_nm&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They include the same variables, except:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The variables are named differently&lt;/LI&gt;
&lt;LI&gt;The variables are in a different order&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Each day, CUSTOMER_SOURCE will be updated with new rows (via a delta load). All rows should then be appended into CUSTOMER_TARGET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the best way to append data from CUSTOMER_SOURCE into CUSTOMER_TARGET?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are the variables of the same type? if Cust_ident is character and Cust_id is numeric it will fail because append will not allow you to append a character to numeric or numeric to character variable.&lt;/P&gt;
&lt;P&gt;Are they the same lengths? If the Cust_ident is 15 characters and Cust_id is 10 you will lose 5 characters after you get the proper syntax to force an unequal length to append at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bigger question might be, why do the variables had different names at all. Read the "source" data so you have the matching variable names (and lengths) and the whole problem goes away.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 14:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763546#M241828</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-24T14:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763785#M241890</link>
      <description>&lt;P&gt;Thanks for the advice! Appending data works very well now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This workload will be using an 'append only' update strategy. In order to prevent re-appending unchanged data, I need to set a checksum (based on all variables). However the actual tables are very wide (around 50 variables). Roughly half of the variables are numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far, I figure that all numeric variables must be converted to characters so that I can use them in an MD5 function, to generate the checksum. But converting half the variables, and listing up all ~50 variables in the MD5 function, seems cumbersome. Is there a more practical way to generate a checksum?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 13:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763785#M241890</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2021-08-25T13:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763786#M241891</link>
      <description>&lt;P&gt;i am not 100% sure that this works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;checksum = md5(cats(of FirstVarInDataset -- LastVarInDataset));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace FirstVar.. and LastVar.. with the actual variable names.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 06:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763786#M241891</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-25T06:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763799#M241900</link>
      <description>&lt;P&gt;This is better&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;checksum = md5(cat(of FirstVarInDataset -- LastVarInDataset));&lt;/LI-CODE&gt;
&lt;P&gt;as missing character variables are otherwise ignored.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 08:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763799#M241900</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-25T08:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763804#M241903</link>
      <description>&lt;P&gt;Or this way. I'm using catx() so that var1=AA, var2=BB will create a different hash value than var1=A, var2=ABB. This is not only theoretical - I've seen this happening in reality.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you've got a lot of rows (=double digit millions) then consider using sha() instead of md5(). I've been in one project where data collision using md5() actually happened.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  set sashelp.class;
  length checksum $32.;
  checksum = put(md5(catx('|',of _all_)),hex32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 09:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763804#M241903</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-25T09:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763805#M241904</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Yes to the formatting, but catx will yield the same value for these 4 values: a, ,b,c and a,b, ,c&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 09:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763805#M241904</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-25T09:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763809#M241905</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;Fair point. Then I guess one would need to generate the concatenation syntax to be on the safe side.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 10:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/763809#M241905</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-25T10:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/764094#M241988</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;One can use the CAT function, or manually concatenate TRIMmed values to shorten the string that's hashed.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 03:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/764094#M241988</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-26T03:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: Appending 1 dataset into another when they've got different variable order &amp; names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/764144#M242015</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;However you do it the 32KB buffer limit needs always to be considered as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  array var_{10} $4000;
  do i=1 to dim(var_);
    var_[i]=put(i,16. -l);
  end;
  checksum1 = md5(cat(of var_1 -- var_10));
  checksum2 = md5(cat(of var_1 -- var_9));
  check_comp= checksum1=checksum2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1629974728815.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63045i90C889EA82781F51/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1629974728815.png" alt="Patrick_0-1629974728815.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 10:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-1-dataset-into-another-when-they-ve-got-different/m-p/764144#M242015</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-26T10:45:35Z</dc:date>
    </item>
  </channel>
</rss>

