<?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: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844025#M333684</link>
    <description>&lt;P&gt;Do you want to compare the&amp;nbsp;&lt;EM&gt;contents&lt;/EM&gt; or the&amp;nbsp;&lt;EM&gt;structures&lt;/EM&gt; of both datasets?&lt;/P&gt;</description>
    <pubDate>Sun, 13 Nov 2022 21:32:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-11-13T21:32:19Z</dc:date>
    <item>
      <title>How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844024#M333683</link>
      <description>&lt;P&gt;I encountered a situation where I just need to compare the two dataset based on the result I need to give a value they are same or not.&lt;/P&gt;
&lt;P&gt;I have the same datasets in different folders. I need to compare both and see they are same ? if they are same then I need to create a variable 'EQUAL'= 'Y' otherwise&amp;nbsp; 'N'. I have the idea of proc compare&amp;nbsp; and I can read the lst file and see if they are equal or not. In my case it's not a suitable idea because I am writing this in macro&amp;nbsp; depending on this further macro will be executed. I thought of counting the observations by outputting the compare dataset but got stuck after words .How we can a achieve this?&lt;/P&gt;
&lt;P&gt;In my example, I tried my best to simulate the condition. Excuse me if I have any errors.&lt;/P&gt;
&lt;P&gt;According to my example ,&lt;/P&gt;
&lt;P&gt;1. I am expecting&amp;nbsp; a variable "EQUAL' = 'Y'&amp;nbsp; ( Even though the lengths are different.)&lt;/P&gt;
&lt;P&gt;2. is it possible we can grab if there is a changes in&amp;nbsp; length, format, labels ? and create a variable with the list of the things changes&amp;nbsp; ( I think its too hard to achieve. if we can not that's ok.)&lt;/P&gt;
&lt;P&gt;Thank you for your inputs.&lt;/P&gt;
&lt;P&gt;How I am expecting the dataset like below . 'LIST' is optional if its too much of work.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1668374099295.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77256i0A499B8AC82194E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1668374099295.png" alt="SASuserlot_0-1668374099295.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
libname folder1 'c:\November';
libname folder2 'c:\December';
*in my case dataset name is same both folders . For the purpose to run the code, I created the same file with different name;

data folder1.x1;
set sashelp.class;
run;

data folder2.x2;
length name $30.;
set x1;
run;

proc compare base= folder1.x1 compare= folder2.x2 out= x3 outnoequal  noprint;
run;
proc sql;
  create table cnt as select count(*) as N from x3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Nov 2022 21:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844024#M333683</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-13T21:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844025#M333684</link>
      <description>&lt;P&gt;Do you want to compare the&amp;nbsp;&lt;EM&gt;contents&lt;/EM&gt; or the&amp;nbsp;&lt;EM&gt;structures&lt;/EM&gt; of both datasets?&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2022 21:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844025#M333684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-13T21:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844026#M333685</link>
      <description>&lt;P&gt;There is a not well known way of doing what you want with PROC COMPARE then checking the return code from the procedure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare base = BaseTable
             compare = CompareTable
             listvar out = difs outnoequal
            ;
run;

%let rc = &amp;amp;sysinfo;

data _null_;
 %* Test for data set label ;
   if &amp;amp;rc = '1'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Data sets have different labels";
 %* Test for data set types ;
   if &amp;amp;rc = '1.'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Data set types differ";
 %* Test for label ;
   if &amp;amp;rc = '1.....'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable has different label";
 %* Test for base observation ;
   if &amp;amp;rc = '1......'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Base data set has observation not in comparison data set";
 %* Test for length ;
   if &amp;amp;rc = '1....'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable has different lengths between the base data set and the comparison data set";
 %* Variable in base data set not in compare data set;
   if &amp;amp;rc ='1..........'b then 
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable in base data set not found in comparison data set";
 %* Comparison data set has variable not in base data set ;
   if &amp;amp;rc = '1...........'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Comparison data set has variable not contained in the base data set";
 %* Test for values ;
   if &amp;amp;rc = '1............'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: A value comparison was unequal";
 %* Conflicting variable types;
   if &amp;amp;rc ='1.............'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Conflicting variable types between the two data sets being compared";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Nov 2022 21:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844026#M333685</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-13T21:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844029#M333687</link>
      <description>&lt;P&gt;Thanks for your response. My major focus in Contents&amp;nbsp; ( if the dataset is same or not irrespective of structural changes)&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2022 22:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844029#M333687</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-13T22:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844030#M333688</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;. I thought the same. how about if we just want to check the content? looking data same or not! like run the compare and out the no equal dataset,----&amp;gt; then count the observation, if count= 0 then datasets are equal otherwise NO? and Whats '&amp;amp;Table" in your code refer to?&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2022 22:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844030#M333688</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-13T22:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844031#M333689</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp; - Sorry, I forgot to correct the code I posted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let table = MyTable;
proc compare base = Folder1.&amp;amp;Table.
             compare = Folder2.&amp;amp;Table.
             listvar out = difs outnoequal
            ;
run;

%let rc = &amp;amp;sysinfo;

data _null_;
 %* Test for data set label ;
   if &amp;amp;rc = '1'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Data sets have different labels";
 %* Test for data set types ;
   if &amp;amp;rc = '1.'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Data set types differ";
 %* Test for label ;
   if &amp;amp;rc = '1.....'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable has different label";
 %* Test for base observation ;
   if &amp;amp;rc = '1......'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Base data set has observation not in comparison data set";
 %* Test for length ;
   if &amp;amp;rc = '1....'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable has different lengths between the base data set and the comparison data set";
 %* Variable in base data set not in compare data set;
   if &amp;amp;rc ='1..........'b then 
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Variable in base data set not found in comparison data set";
 %* Comparison data set has variable not in base data set ;
   if &amp;amp;rc = '1...........'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Comparison data set has variable not contained in the base data set";
 %* Test for values ;
   if &amp;amp;rc = '1............'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: A value comparison was unequal";
 %* Conflicting variable types;
   if &amp;amp;rc ='1.............'b then
      put "&amp;lt;&amp;lt;&amp;lt;&amp;lt; &amp;amp;table.: Conflicting variable types between the two data sets being compared";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yes, you could just check the COMPARE output dataset and if there are any rows that is evidence there are data differences between the two tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2022 22:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844031#M333689</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-11-13T22:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844079#M333717</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
That is easy if these two tables have the same variable name with same order and type.
*/





libname folder1 'c:\temp\old';
libname folder2 'c:\temp\new';

data folder1.x1;
set sashelp.class;
run;
data folder2.x2;
set sashelp.class;
run;

data folder1.y1;
set sashelp.heart;
run;
data folder2.y2;
set sashelp.heart;
if _n_=1 then call missing(of _numeric_);
run;






%macro compare_dsn(first=,second= , output=);
proc sql;
create table &amp;amp;output. as
(
select * from  &amp;amp;first.
except
select * from  &amp;amp;second.
)
union
(
select * from  &amp;amp;second.
except
select * from  &amp;amp;first.
)
;
quit;
%mend;
proc datasets library=work kill memtype=data nolist nodetails;
quit;
%compare_dsn(first= folder1.x1,second= folder2.x2 , output=x)
%compare_dsn(first= folder1.y1,second= folder2.y2 , output=y)

/*generate the comparing report   */
proc sql;
select memname,ifc(nlobs=0,'Y','N') as equal
 from dictionary.tables 
  where libname='WORK' ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 11:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844079#M333717</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-14T11:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare same datasets in two different locations(Folder) and Create the  Boolean (Y/N)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844543#M333885</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 01:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-same-datasets-in-two-different-locations-Folder/m-p/844543#M333885</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-11-16T01:48:50Z</dc:date>
    </item>
  </channel>
</rss>

