<?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: compare two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295047#M61616</link>
    <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for giving me a chance to learn.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following code and identified the other coloumns. now how to give all these in&amp;nbsp;compare_col macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=have2 out=contents2 noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=contents2;&lt;BR /&gt;by varnum;&lt;BR /&gt;where varnum &amp;gt; 3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Raju&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12902iCC8513DDC1264062/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="assign.PNG" title="assign.PNG" /&gt;</description>
    <pubDate>Tue, 30 Aug 2016 04:49:02 GMT</pubDate>
    <dc:creator>Raj_C</dc:creator>
    <dc:date>2016-08-30T04:49:02Z</dc:date>
    <item>
      <title>compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294692#M61495</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS dataset 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;/P&gt;&lt;P&gt;input id var $ sex $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10 bala m&lt;/P&gt;&lt;P&gt;10 raju m&lt;/P&gt;&lt;P&gt;11 chak f&lt;/P&gt;&lt;P&gt;11 sudh m&lt;/P&gt;&lt;P&gt;12 keer f&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS dataset 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;input id var $ sex $ sal;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10 balaa m 200&lt;/P&gt;&lt;P&gt;11 raju f 100&lt;/P&gt;&lt;P&gt;12 chak m 400&lt;/P&gt;&lt;P&gt;11 sudh m 500&lt;/P&gt;&lt;P&gt;12 keer m 350&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we need to compare have1 SAS dataset with have2 SAS dataset and output should contain unequal data (if any new variable is recorded that also we need to report in the output for e.g. sal is the extra variable here).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Raju&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 04:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294692#M61495</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-29T04:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294697#M61496</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id var $ sex $;
datalines;
10 bala m
10 raju m
11 chak f
11 sudh m
12 keer f
;
run;
 
 

 
data have2;
input id var $ sex $ sal ;
datalines;
10 balaa m 200
11 raju f 100
12 chak m 400
11 sudh m 500
12 keer m 350
;
run;
proc sort data=have1 out=have1_sorted;
by id;run;
proc sort data=have2 out=have2_sorted;;
by id;run;

proc compare base=have1_sorted compare=have2_sorted;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If input dataset are sorted then no need to add proc sort code.&lt;/P&gt;&lt;P&gt;It will generate a report that can be saved as pdf file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do check the proc compare it has much more options to use. I have given example of the most simplest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294697#M61496</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-29T05:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294699#M61497</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even I tried this one, but how to report it in Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for the following code the output should look like the attached screenshot in Excelsheet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input id var $ sex $;&lt;BR /&gt;datalines;&lt;BR /&gt;10 bala m&lt;BR /&gt;11 chak f&lt;BR /&gt;12 keer f&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data have2;&lt;BR /&gt;input id var $ sex $;&lt;BR /&gt;datalines;&lt;BR /&gt;10 balaa m&lt;BR /&gt;11 sudh m&lt;BR /&gt;12 chak m&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294699#M61497</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-29T05:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294700#M61498</link>
      <description>&lt;P&gt;Kindly find the attched screenshot.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12889i594C1EA4B3610F6B/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Compare.PNG" title="Compare.PNG" /&gt;</description>
      <pubDate>Mon, 29 Aug 2016 05:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294700#M61498</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-29T05:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294703#M61500</link>
      <description>&lt;P&gt;Use a SQL merge with a case statement to check for your conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use proc export to get data to excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 06:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294703#M61500</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-29T06:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294704#M61501</link>
      <description>&lt;P&gt;Use a SQL merge with a case statement to check for your conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use proc export to get data to excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 06:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294704#M61501</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-29T06:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294705#M61502</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have1 out=have1_sorted;
by id;run;
proc sort data=have2 out=have2_sorted;;
by id;run;

proc transpose data=have1 out=have1_trans (rename= (_name_=col_name));
by id;
var var sex ;
run;

proc transpose data=have2 out=have2_trans(rename= (_name_=col_name)) ;
by id;
var var sex sal;
run;

proc sql;
create table compare_table
as
select coalesce(a.id,b.id) as ID,coalesce(a.col_name,b.col_name) as var
, a.col1 as old_val
,b.col1 as new_val
,case when a.col1 &amp;lt;&amp;gt; b.col1 and a.id= b.id then 'Modified'
      when a.col1 &amp;lt;&amp;gt; b.col1 and a.id=. then 'Added'
      when a.col1 &amp;lt;&amp;gt; b.col1 and b.id=. then 'Deleted' end as remark 

from have1_trans a
full join have2_trans b
on a.id = b.id and a.col_name = b.col_name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can then export the final table to xls using proc export.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 06:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294705#M61502</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-29T06:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294707#M61503</link>
      <description>&lt;P&gt;For testing purpose, I have kept all the rows. You can filter the rows from output dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 06:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/294707#M61503</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-29T06:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295003#M61597</link>
      <description>&lt;P&gt;Hi Rahul &amp;amp; SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;/P&gt;&lt;P&gt;input id var $ record sex $ sal fold $ rate;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10 bala 1 m 200 v1 5&lt;/P&gt;&lt;P&gt;10 bala 2 m 300 v1 4&lt;/P&gt;&lt;P&gt;10 bala 3 f 200 a2 6&lt;/P&gt;&lt;P&gt;11 sri 1 m 204 d2 2&lt;/P&gt;&lt;P&gt;11 sri 2 f 408 d4 3&lt;/P&gt;&lt;P&gt;12 koti 1 m 490 v3 4&lt;/P&gt;&lt;P&gt;12 koti 3 f 300 b3 5&lt;/P&gt;&lt;P&gt;12 koti 5 m 203 n4 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have2;&lt;/P&gt;&lt;P&gt;input id var $ record sex $ sal fold $ rate;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10 bala 1 f 220 v1 5&lt;/P&gt;&lt;P&gt;10 bala 2 m 300 v1 4&lt;/P&gt;&lt;P&gt;10 bala 3 m 230 a2 7&lt;/P&gt;&lt;P&gt;11 sri 1 m 204 v2 2&lt;/P&gt;&lt;P&gt;11 sri 2 m 468 d4 3&lt;/P&gt;&lt;P&gt;12 koti 1 f 491 n3 4&lt;/P&gt;&lt;P&gt;12 koti 3 m 300 b3 5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12 koti 5 f 203 n4 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;12 koti 6 m 213 n4 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now by keeping id, var and record as key coloumns&amp;nbsp;(for e.g. (10 bala 1) record of have1 SAS dataset should compare with (10 bala 1) record of have2 SAS dataset) we need to compare rest of all variables and the output should be look like the screenshot attached&amp;nbsp;which&amp;nbsp;shown earlier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if any new record comes (for e.g. (12 koti) is having two records in have1 SAS dataset but in have2 (12 koti 6) added so in this case it should show like new record added.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you Rahul for your quick response and patience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Raju&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2016 23:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295003#M61597</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-29T23:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295039#M61612</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input id var $ record sex $ sal fold $ rate;
datalines;
10 bala 1 m 200 v1 5
10 bala 2 m 300 v1 4
10 bala 3 f 200 a2 6
11 sri 1 m 204 d2 2
11 sri 2 f 408 d4 3
12 koti 1 m 490 v3 4
12 koti 3 f 300 b3 5
12 koti 5 m 203 n4 3
;
run;
 
data have2;
input id var $ record sex $ sal fold $ rate;
datalines;
10 bala 1 f 220 v1 5
10 bala 2 m 300 v1 4
10 bala 3 m 230 a2 7
11 sri 1 m 204 v2 2
11 sri 2 m 468 d4 3
12 koti 1 f 491 n3 4
12 koti 3 m 300 b3 5
12 koti 5 f 203 n4 3
12 koti 6 m 213 n4 3
;
run;

%let key_col=id var  record ;
%let compare_col=sex sal fold rate;

%let key_col_cnt=%sysfunc(countw(&amp;amp;key_col));
%macro select_col;
%do i=1 %to &amp;amp;key_col_cnt;
%let col=%sysfunc(scan( &amp;amp;key_col,&amp;amp;i));
coalesce(a.&amp;amp;col,b.&amp;amp;col) as &amp;amp;col,
%end;
%mend;



%macro join_cond;
%do i=1 %to &amp;amp;key_col_cnt;
%let col=%sysfunc(scan( &amp;amp;key_col,&amp;amp;i));
 a.&amp;amp;col =b.&amp;amp;col and 
%end;
%mend;


proc sort data=have1 out=have1_sorted;
by &amp;amp;key_col ;run;
proc sort data=have2 out=have2_sorted;;
by &amp;amp;key_col ;run;

proc transpose data=have1 out=have1_trans (rename= (_name_=col_name));
by &amp;amp;key_col ;
var  &amp;amp;compare_col ;
run;

proc transpose data=have2 out=have2_trans(rename= (_name_=col_name)) ;
by &amp;amp;key_col ;
var &amp;amp;compare_col;
run;

proc sql;
create table compare_table
as
select %select_col
coalesce(a.col_name,b.col_name) as variable_name
,strip(a.col1) as old_val
,strip(b.col1) as new_val
,case when strip(a.col1) &amp;lt;&amp;gt; strip(b.col1) and a.id= b.id and a.record =b.record then 'Modified'
      when strip(a.col1) &amp;lt;&amp;gt; strip(b.col1) and a.id=. then 'Added'
      when strip(a.col1) &amp;lt;&amp;gt; strip(b.col1) and b.id=. then 'Deleted' end as remark 

from have1_trans a
full join have2_trans b
on %join_cond
 a.col_name = b.col_name;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Automated the above code using two macro variable key_col and compare_col.&lt;/P&gt;&lt;P&gt;User need to supply value to these two macro variables and proc sql changes would be handled itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let key_col=id var  record ;
%let compare_col=sex sal fold rate;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here there is an assumption key_col and compare_col &amp;nbsp; columns should be present both&amp;nbsp;in have1 and have2.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 03:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295039#M61612</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-30T03:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295041#M61613</link>
      <description>&lt;P&gt;You are awesome Rahul.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as you said&amp;nbsp;user will supply the key coloums for key_col macro but can we a code like to take rest all coloums as&amp;nbsp;compare_col.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 04:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295041#M61613</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-30T04:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295043#M61614</link>
      <description>&lt;P&gt;Surely, you can take it as an excerise yourself. List all the columns using proc dataset and remove key_col. The left would be compare_col list.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 04:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295043#M61614</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-30T04:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295047#M61616</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for giving me a chance to learn.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried the following code and identified the other coloumns. now how to give all these in&amp;nbsp;compare_col macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=have2 out=contents2 noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=contents2;&lt;BR /&gt;by varnum;&lt;BR /&gt;where varnum &amp;gt; 3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Raju&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12902iCC8513DDC1264062/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="assign.PNG" title="assign.PNG" /&gt;</description>
      <pubDate>Tue, 30 Aug 2016 04:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295047#M61616</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-08-30T04:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295049#M61617</link>
      <description>&lt;P&gt;Please see the recently update macro example section to find the solution to your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/tac-p/292711#M1604" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/tac-p/292711#M1604&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 04:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295049#M61617</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-30T04:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295052#M61618</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have2 out=contents2 noprint;
run;

proc sql noprint;
select name into :compare_col&amp;nbsp;separated by ' '
from contents2
where varnum&amp;gt;3;
quit;
%put &amp;amp;compare_col&amp;nbsp;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is similar to what you have written below. But it can fail if key column lie after varnum &amp;gt;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do refer to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you think you got answer to your problem. Please mark it as solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 05:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295052#M61618</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-30T05:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295099#M61628</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I was going through the code I got a doubt.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; join_cond&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;key_col_cnt&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; col&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;key_col&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col and 
&lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here in Line4 . How SAS consider this "AND" here.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col and &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you explain this why "And" is here and how it works Even in the&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;coalesce&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; as &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Select_Col macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;SJ&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 12:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295099#M61628</guid>
      <dc:creator>SJN</dc:creator>
      <dc:date>2016-08-30T12:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295105#M61631</link>
      <description>&lt;P&gt;I required joining condition which is highlighted below, so and keyword was required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col and &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from have1_trans a&lt;BR /&gt;full join have2_trans b&lt;BR /&gt;on&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; a.id = b.id and &lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; a.var=b.var and&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; a.record=b.record and&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;a.col_name = b.col_name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For select I need following&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;coalesce&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; as &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;coalesce(a.id,b.id) as ID&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;,coalesce(a.var,b.var) as var&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;,coalesce(a.record,b.record) as record&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 11:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295105#M61631</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-30T11:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295127#M61639</link>
      <description>&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;col and &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;once these variables are resolved, SAS consider as text and use that in join clause. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run the macro alone why its not working. Correct me if I'm wrong.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 12:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295127#M61639</guid>
      <dc:creator>SJN</dc:creator>
      <dc:date>2016-08-30T12:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295255#M61686</link>
      <description>&lt;P&gt;If I run this code what would be the output&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a.id = b.id and 
a.var=b.var and
a.record = b.record &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It would throw the error. The above piece of code do not make any sense. But if it used in the join condition, it works well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I am able to answer you.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 17:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/295255#M61686</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-08-30T17:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: compare two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/296301#M62030</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Rahul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had refer Reeza's post and I used following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let key_col=id var record;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro rename;&lt;BR /&gt;%let word_cnt=%sysfunc(countw(&amp;amp;key_col));&lt;BR /&gt;%do i = 1 %to &amp;amp;word_cnt;&lt;BR /&gt;%let temp=%qscan(%bquote(&amp;amp;key_col),&amp;amp;i);&lt;BR /&gt;&amp;amp;temp = _&amp;amp;temp&lt;BR /&gt;%end;&lt;BR /&gt;%mend rename;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;set have2(rename=(%unquote(%rename)));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I am getting key variables starting with _ (like _id _var _record) but now how to assign&amp;nbsp;other variables to&amp;nbsp;compare_col.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I am new to macros requesting you to kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;&lt;P&gt;Raju&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 11:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-datasets/m-p/296301#M62030</guid>
      <dc:creator>Raj_C</dc:creator>
      <dc:date>2016-09-03T11:55:37Z</dc:date>
    </item>
  </channel>
</rss>

