<?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: Dataset comparison in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546132#M8170</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
if _n_=1 then do;
   dcl hash H (dataset:'test2(rename=(age=_age sex=_sex))') ;
   h.definekey  ("name") ;
   h.definedata ("_age", "_sex") ;
   h.definedone () ;
  _age=.;
	_sex=' ';
   end;
do until(lr);
set test1 end=lr;
rc=h.find();
variable_status = catx(',',ifc(age ne _age,'AGE',' '),ifc(sex ne _sex,'SEX',' '));
output;
end;
stop;
drop rc _:;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Mar 2019 13:23:30 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-03-26T13:23:30Z</dc:date>
    <item>
      <title>Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546067#M8151</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;I have 2 datasets , which contain the same variables and all variables have same data type and label in both&lt;/P&gt;&lt;P&gt;ex :&lt;/P&gt;&lt;P&gt;Current dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test1;&lt;BR /&gt;input name $10 age sex;&lt;BR /&gt;cards;&lt;BR /&gt;a 5 m&lt;BR /&gt;b 7 f&lt;BR /&gt;c 6 f&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;old generated dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test2;&lt;BR /&gt;input name $10 age sex;&lt;BR /&gt;cards;&lt;BR /&gt;a 5 m&lt;BR /&gt;b 8 f&lt;BR /&gt;c 7 M&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need output as mentioned below,a new variable needed which contain the details of column name if any data got change in comparison of old dataset and new dataset.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;final output needed as :&lt;/P&gt;&lt;P&gt;name age sex variable_status&lt;BR /&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp;m&lt;BR /&gt;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age&lt;BR /&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age,sex&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;thank you in advance !!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 10:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546067#M8151</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2019-03-26T10:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546070#M8152</link>
      <description>&lt;P&gt;First lets sort out your test data as it was not correct.&amp;nbsp; Then we use proc compare to get differences.&amp;nbsp; From that output you can then get the results you want:&lt;/P&gt;
&lt;PRE&gt;data test1;
  input name $ age sex $;
cards;
a 5 m
b 7 f
c 6 f
;
run;

data test2;
  input name $ age sex $;
cards;
a 5 m
b 8 f
c 7 M
;
run;

proc compare base=test1 comp=test2 out=want outnoequal outbase outcomp outdif noprint;
  id name;
run;

data want;
  set want;
  length result $100;
  if _type_="DIF" then do;
    if name ne lag(name) then result=catx(",",result,"name");
    if age ne lag(age) then result=catx(",",result,"age");
    if sex ne lag(sex) then result=catx(",",result,"sex");
    output;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 10:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546070#M8152</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-03-26T10:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546079#M8155</link>
      <description>&lt;P&gt;Since you want the orginal (base values) preserved, use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test1;
input name $ age sex :$1.;
cards;
a 5 m
b 7 f
c 6 f
;
run;

Data test2;
input name $ age sex :$1.;
cards;
a 5 m
b 8 f
c 7 M
;
run;

proc compare
  base=test1
  compare=test2
  out=comp
  outdif
  outbase
  noprint
;
id name;
run;

data want;
set comp (rename=(age=_age sex=_sex));
by name;
retain age sex " ";
if first.name /* BASE obs */
then do;
  age = _age;
  sex = _sex;
end;
if last.name /* DIF obs */
then do;
  variable_status = catx(',',ifc(_age ne 0,'age',''),ifc(_sex ne '.','sex',''));
  output;
end;
keep name age sex variable_status;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                      variable_
name    age    sex     status

 a       5      m              
 b       7      f      age     
 c       6      f      age,sex 
&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 11:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546079#M8155</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-26T11:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546126#M8168</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test1;
input name $ age sex :$1.;
cards;
a 5 m
b 7 f
c 6 f
;
run;

Data test2;
input name $ age sex :$1.;
cards;
a 5 m
b 8 f
c 7 M
;
run;

proc sql;
create table want as
select a.*,catx(',',ifc(a.age ne b.age,'AGE',' '),ifc(a.sex ne b.sex,'SEX',' ')) as variable_status
from test1 a left join test2 b
on a.name=b.name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546126#M8168</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-26T13:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546132#M8170</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
if _n_=1 then do;
   dcl hash H (dataset:'test2(rename=(age=_age sex=_sex))') ;
   h.definekey  ("name") ;
   h.definedata ("_age", "_sex") ;
   h.definedone () ;
  _age=.;
	_sex=' ';
   end;
do until(lr);
set test1 end=lr;
rc=h.find();
variable_status = catx(',',ifc(age ne _age,'AGE',' '),ifc(sex ne _sex,'SEX',' '));
output;
end;
stop;
drop rc _:;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546132#M8170</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-26T13:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546138#M8171</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*If sorted by name*/
data want;
merge test1 test2(rename=(age=_age sex=_sex));
by name;
variable_status = catx(',',ifc(age ne _age,'AGE',' '),ifc(sex ne _sex,'SEX',' '));
drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546138#M8171</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-26T13:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset comparison</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546170#M8173</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153275"&gt;@singhsahab&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello ,&lt;/P&gt;
&lt;P&gt;I have 2 datasets , which contain the same variables and all variables have same data type and label in both&lt;/P&gt;
&lt;P&gt;ex :&lt;/P&gt;
&lt;P&gt;Current dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data test1;&lt;BR /&gt;input name $10 age sex;&lt;BR /&gt;cards;&lt;BR /&gt;a 5 m&lt;BR /&gt;b 7 f&lt;BR /&gt;c 6 f&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;old generated dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data test2;&lt;BR /&gt;input name $10 age sex;&lt;BR /&gt;cards;&lt;BR /&gt;a 5 m&lt;BR /&gt;b 8 f&lt;BR /&gt;c 7 M&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need output as mentioned below,a new variable needed which contain the details of column name if any data got change in comparison of old dataset and new dataset.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;final output needed as :&lt;/P&gt;
&lt;P&gt;name age sex variable_status&lt;BR /&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp;m&lt;BR /&gt;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age&lt;BR /&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; f&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age,sex&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;thank you in advance !!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please explain exactly how you intend to use the variable_status variable. Many times placing multiple values into a single variable causes much more work down the line. Also, how many variables do you have? You likely will need to consider explicitly setting a length for the variable as if you have dozens of variable the combine lengths of the names plus the commas may exceed the default length for the likely functions to combine the variable names together. Since variable names can contain 32 characters then potentially as few as 10 variables will require: 10*32+9 or 329&amp;nbsp;characters to hold the result.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Dataset-comparison/m-p/546170#M8173</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-26T14:40:09Z</dc:date>
    </item>
  </channel>
</rss>

