<?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 base sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115797#M23864</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you please help me on below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Want to compare two datasets(new1 and old1) on multiple columns, also has unique key variable on both datasets&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if Unique key variable and all remaining columns are matched in two datasets (new1 and old1) then write status as "Equal"&lt;BR /&gt;if Unique key variable is existing in new1 and not existing in old1&amp;nbsp; then write status as "New"&lt;BR /&gt;if Unique key variable is not existing in new1 and existing in old1 on key variable then write status as "Deleted"&lt;BR /&gt;if Unique key variable is matched and all remaining columns are not matched on both new1 and old1 datasets then write status as "Updated"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Apr 2013 16:51:07 GMT</pubDate>
    <dc:creator>sunilreddy</dc:creator>
    <dc:date>2013-04-22T16:51:07Z</dc:date>
    <item>
      <title>base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115797#M23864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you please help me on below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Want to compare two datasets(new1 and old1) on multiple columns, also has unique key variable on both datasets&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if Unique key variable and all remaining columns are matched in two datasets (new1 and old1) then write status as "Equal"&lt;BR /&gt;if Unique key variable is existing in new1 and not existing in old1&amp;nbsp; then write status as "New"&lt;BR /&gt;if Unique key variable is not existing in new1 and existing in old1 on key variable then write status as "Deleted"&lt;BR /&gt;if Unique key variable is matched and all remaining columns are not matched on both new1 and old1 datasets then write status as "Updated"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 16:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115797#M23864</guid>
      <dc:creator>sunilreddy</dc:creator>
      <dc:date>2013-04-22T16:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115798#M23865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by compare "on multiple columns"? Compare the values of some, any&amp;nbsp; or all variables other than the key for each matching key? or only for those in New1 or only in Old1? Do you want to create a data set with the "Equal" "New" or "Deleted" values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would start by sorting each dataset on the key variable.&lt;/P&gt;&lt;P&gt;Then&lt;/P&gt;&lt;P&gt;Proc compare base=old1 compare=new1; Run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are options for compare that allow selecting results from the base or the compare dataset, but this should get you started as to what is going on in the data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 17:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115798#M23865</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-04-22T17:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115799#M23866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The way I read your Q&lt;/P&gt;&lt;P&gt;you are looking to identify the differences between two snapshots.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This macro handles that problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www.sascommunity.org/wiki/Macro_Extract" title="http://www.sascommunity.org/wiki/Macro_Extract"&gt;http://www.sascommunity.org/wiki/Macro_Extract&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ron Fehd&amp;nbsp; transaction maven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 17:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115799#M23866</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2013-04-22T17:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115800#M23867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way you have presanted your query, possible solution is as follow...I hope this works...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example, i have created dataset containing households with sales and units...that is table_A contains hhd,sales and units for one period and table_B contains hhd,sales and units for second period...and compare both period households and assign your mentioned conditions...In my code, HHD is unique key in both the datasets...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table_A;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input hhd $ sales units;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;A 10 4&lt;BR /&gt;B 20 5&lt;BR /&gt;C 30 2&lt;BR /&gt;D 40 3&lt;BR /&gt;F 60 1&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data table_B;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input hhd $ sales units;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; cards;&lt;BR /&gt;A 10 4&lt;BR /&gt;B 20 5&lt;BR /&gt;C 30 2&lt;BR /&gt;D 40 3&lt;BR /&gt;E 50 4&lt;BR /&gt;D 60 .&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sort data = table_A;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by hhd;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = table_B;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by hhd;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro compare;&lt;/P&gt;&lt;P&gt;proc contents data = table_A out = list_A(keep = name) noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data = table_B out = list_B(keep = name) noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp; select count(name) into :count_A&lt;BR /&gt;&amp;nbsp; from list_A; &lt;/P&gt;&lt;P&gt;&amp;nbsp; select count(name) into :count_B&lt;BR /&gt;&amp;nbsp; from list_B;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :name_A separated by " "&lt;BR /&gt;&amp;nbsp; from list_A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :name_B separated by " "&lt;BR /&gt;&amp;nbsp; from list_B;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets nolist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; modify table_B;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; rename %do i = 1 %to &amp;amp;count_B.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %scan(&amp;amp;name_B.,&amp;amp;i.) = %scan(&amp;amp;name_B.,&amp;amp;i.)_Y2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets nolist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; modify table_A;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; rename %do i = 1 %to &amp;amp;count_A.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %scan(&amp;amp;name_A.,&amp;amp;i.) = %scan(&amp;amp;name_A.,&amp;amp;i.)_Y1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data both(drop = _temp: in_A in_B);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; retain hhd sales_Y1 units_Y1 sales_Y2 units_Y2 item;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; length item $10.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; merge table_A(in = a rename = (hhd_Y1 = hhd))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table_B(in = b rename = (hhd_Y2 = hhd));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by hhd;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; in_A = a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; in_B = b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do i = 2 %to &amp;amp;count_B.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _temp&amp;amp;i. = %scan(&amp;amp;name_B.,&amp;amp;i.)_Y2 - %scan(&amp;amp;name_A.,&amp;amp;i.)_Y1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (in_A = 1 and in_B = 1) and _temp&amp;amp;i. = 0 then item = "Equal";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if in_a = 0 and in_B = 1 then item = "New";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if in_a = 1 and in_B = 0 then item = "Deleted";&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (in_a = 1 and in_B = 1) and (_temp&amp;amp;i. NE 0 or _temp&amp;amp;i. = .) then item = "Updated";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%compare;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Urvish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 18:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115800#M23867</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-04-22T18:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115801#M23868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another approach using Metadata, raw input borrowed from Urvish:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table_A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input hhd $ sales units;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;A 10 4&lt;/P&gt;&lt;P&gt;B 20 5&lt;/P&gt;&lt;P&gt;C 30 2&lt;/P&gt;&lt;P&gt;D 40 3&lt;/P&gt;&lt;P&gt;F 60 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table_B;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input hhd $ sales units;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;A 10 4&lt;/P&gt;&lt;P&gt;B 20 5&lt;/P&gt;&lt;P&gt;C 30 2&lt;/P&gt;&lt;P&gt;D 40 3&lt;/P&gt;&lt;P&gt;E 50 4&lt;/P&gt;&lt;P&gt;D 60 .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = table_A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by hhd;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = table_B;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by hhd;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql NOPRINT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select cats(name,'=','new_',name) into :ren separated by ' '&lt;/P&gt;&lt;P&gt;from dictionary.columns&lt;/P&gt;&lt;P&gt;where libname='WORK'&lt;/P&gt;&lt;P&gt;AND MEMNAME='TABLE_A'&lt;/P&gt;&lt;P&gt;AND UPCASE(NAME) NE 'HHD'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT CATS(NAME,'=','NEW_',NAME) INTO :COMP SEPARATED BY ' AND '&lt;/P&gt;&lt;P&gt;from dictionary.columns&lt;/P&gt;&lt;P&gt;where libname='WORK'&lt;/P&gt;&lt;P&gt;AND MEMNAME='TABLE_A'&lt;/P&gt;&lt;P&gt;AND UPCASE(NAME) NE 'HHD'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge TABLE_A(IN=OLD) TABLE_B(IN=NEW RENAME=(&amp;amp;REN));&lt;/P&gt;&lt;P&gt;&amp;nbsp; BY HHD;&lt;/P&gt;&lt;P&gt;LENGTH STATUS $8.;&lt;/P&gt;&lt;P&gt;IF OLD AND NEW THEN DO;&lt;/P&gt;&lt;P&gt;IF &amp;amp;COMP THEN STATUS='EQUAL';&lt;/P&gt;&lt;P&gt;ELSE STATUS='UPDATED';&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;ELSE IF OLD AND NOT NEW THEN STATUS='DELETED';&lt;/P&gt;&lt;P&gt;ELSE IF NEW AND NOT OLD THEN STATUS='NEW';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115801#M23868</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-22T19:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115802#M23869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Haikuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code is also meeting the requirement...Good one...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 05:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/base-sas/m-p/115802#M23869</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-04-23T05:25:16Z</dc:date>
    </item>
  </channel>
</rss>

