<?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: comparing all variable values between two datasets and high-light mismatch in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843851#M333610</link>
    <description>Thank you so much sir</description>
    <pubDate>Fri, 11 Nov 2022 19:55:47 GMT</pubDate>
    <dc:creator>abraham1</dc:creator>
    <dc:date>2022-11-11T19:55:47Z</dc:date>
    <item>
      <title>comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843038#M333335</link>
      <description>&lt;P&gt;Hi everyone&lt;/P&gt;
&lt;P&gt;I have two datasets from phase I and phase 2 trials. I need to combine the data and compare each variable value from phase2 to each variable from phase 1 and high-light all mismatch value with red color.&lt;/P&gt;
&lt;P&gt;Along with this, a new column needs to be inserted ' comment' where if data are matching, it should populate 'matching'. For every mismatch, it will display which variable mismatch and the respective value in parenthesis. Multiple mismatches should be separated by comma.&lt;/P&gt;
&lt;P&gt;I need to repeat the same process for 500 variables and lakh of records in new dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data phase1;
input PID AGE Visit	phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
;
run;

data phase2;
input PID AGE Visit	phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
;
run;
proc sort data=phase1;by pid visit phase;run;
proc sort data=phase2;by pid visit phase;run;
proc sql;
create table final as
select * from phase1 union all
select * from phase2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Output&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2022-11-08_11-59-07.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77064i21CFADC92CA07133/image-size/large?v=v2&amp;amp;px=999" role="button" title="2022-11-08_11-59-07.png" alt="2022-11-08_11-59-07.png" /&gt;&lt;/span&gt;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 06:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843038#M333335</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-11-08T06:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843050#M333336</link>
      <description>&lt;P&gt;Why is "comment" empty in the first six obs in the result?&lt;/P&gt;
&lt;P&gt;You can't change the background colour of cells in a dataset, so you need to create a report. Which file format is expected?&lt;/P&gt;
&lt;P&gt;In the data shown all variables that need to be compared are alphanumeric. Is this true for all variables in your original data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;EDIT&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4" color="#FF6600"&gt;Please check the data you have posted an align it with the expected result. The value "upset" is not in the data shown.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843050#M333336</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-08T08:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843051#M333337</link>
      <description>&lt;P&gt;Thank you sir for checking&lt;/P&gt;
&lt;P&gt;As I need to compare new dataset i.e. phase 2 to phase 1 (master sheet), the comment column should display discrepancy only on new dataset. Therefore phase 1 comment column kept blank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to generate the report in excel format for analysis.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, some variables contain values of numeric, some character and some alphanumeric.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843051#M333337</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-11-08T08:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843052#M333338</link>
      <description>&lt;P&gt;Have checked the PROC COMPARE to achieve the differences, though it is not reported in the required format.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843052#M333338</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2022-11-08T08:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843055#M333339</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357256"&gt;@abraham1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you sir for checking&lt;/P&gt;
&lt;P&gt;As I need to compare new dataset i.e. phase 2 to phase 1 (master sheet), the comment column should display discrepancy only on new dataset. Therefore phase 1 comment column kept blank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to generate the report in excel format for analysis.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;No, some variables contain values of numeric, some character and some alphanumeric.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then please change the data you have posted to match what you really have.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843055#M333339</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-08T08:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843064#M333342</link>
      <description>&lt;P&gt;I have added one numeric variable ('dose'). please have a look.&lt;/P&gt;
&lt;P&gt;The discrepancy in last variable if found during comparison will be added into comment column. I have not updated the final output. Hope it is fine.&lt;/P&gt;
&lt;PRE&gt;data phase1;
input PID AGE Visit	phase event $ drug $ study $ dose;
cards;
101 23 1 1 asthma parace Yes 5
102 32 1 1 asthma sinarest Yes 10
101 23 2 1 headache drg1 No 5
103 43 1 1 vomit drg4 Yes 5 
103 43 2 1 pain drg5 No 100
103 43 3 1 pain drg5 Yes 500
;
run;

data phase2;
input PID AGE Visit	phase event $ drug $ study $ dose;
cards;
101 23 1 2 asthma parace Yes 5
102 32 1 2 asthma . Yes 5
101 23 2 2 acidity drg1 No 5
103 43 1 2 vomit drg4 Yes 100
103 43 2 2 pain drg5 No 100
103 43 4 2 pan drg5 Yes 500
107 43 3 2 pain drg5 Yes 200
;
run;
proc sort data=phase1;by pid visit phase;run;
proc sort data=phase2;by pid visit phase;run;
proc sql;
create table final as
select * from phase1 union all
select * from phase2;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843064#M333342</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-11-08T08:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843094#M333349</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data phase1;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
;
run;

data phase2;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
;
run;








libname old v9 'c:\temp\old';
data old.phase;
 set phase1;
 drop phase;
run;
libname new v9 'c:\temp\new';
data new.phase;
 set phase2;
 drop phase;
run;

%macro type_two(dsn=,subjid=,key=);
proc datasets library=work kill nolist nodetails;quit;
proc sort data=old.&amp;amp;dsn. out=old;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc sort data=new.&amp;amp;dsn. out=new;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc compare data=old compare=new noprint out=diff_&amp;amp;dsn.;
id &amp;amp;subjid. &amp;amp;key. ;
run;
data call_define(where=(upcase(vname) not in ("%upcase(&amp;amp;subjid.)"  "%upcase(&amp;amp;key.)" )));
 set diff_&amp;amp;dsn.(drop=_TYPE_ _OBS_  );
 length vname $ 40;
 array n{*} _numeric_;
 array c{*} _character_;
 do i=1 to dim(n);
   if n{i} not in (. 0) then do;vname=vname(n{i});output;end;
 end;
 do i=1 to dim(c);
   if findc(c{i},'X') then do;vname=vname(c{i});output;end;
 end;
keep &amp;amp;subjid. &amp;amp;key. vname;
run;
filename t temp;
data _null_;
 set call_define;
 file t;
 put "if &amp;amp;subjid.='" &amp;amp;subjid. "' and &amp;amp;key.='" &amp;amp;key. "' then call define('" vname "','style','style={background=red}');";
run;
data &amp;amp;dsn.;
if _n_=1 then do;
 if 0 then set new.&amp;amp;dsn.;
 if 0 then set old.&amp;amp;dsn.;
 declare hash h(dataset:"old.&amp;amp;dsn.");
 h.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h.definedone();

 declare hash h1(dataset:'call_define');
 h1.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h1.definedone();
end;
 set new.&amp;amp;dsn.;
 length new_change $ 40;
 if h.check() ne 0 then new_change='new' ;
 if h1.check() = 0 then new_change='change' ;
label new_change='new/change';
run;
ods excel file="c:\temp\want.xlsx" options(sheet_name="&amp;amp;dsn." autofilter='all' ) ;
proc report data=&amp;amp;dsn. split='*'  nowd;
column _all_ dummy;
define _all_/display;
define dummy/computed noprint;
compute dummy;
%include t;
if new_change='new' then call define(_row_,'style','style={background=red}');
endcomp;
run;
ods excel close;
%mend;



%type_two(dsn=phase,subjid=pid ,key=visit )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1667907678009.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77075iCF411F3CEE5A394D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1667907678009.png" alt="Ksharp_0-1667907678009.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 11:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843094#M333349</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-08T11:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843851#M333610</link>
      <description>Thank you so much sir</description>
      <pubDate>Fri, 11 Nov 2022 19:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/843851#M333610</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-11-11T19:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879457#M347426</link>
      <description>&lt;P&gt;Hi Sir,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for detailed information on the question. I have one question, can we please help me what to do if the data from target is deleted while comparing to source?&amp;nbsp;&amp;nbsp; For the current context only. I just add a new record in the phase1 dataset with subject record 104. What to do if the 104 record is deleted in the phase2 dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data phase1;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
104 20 3 1 fever drg6 No
;
run;

data phase2;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 22:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879457#M347426</guid>
      <dc:creator>possible</dc:creator>
      <dc:date>2023-06-06T22:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879513#M347455</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Try this one*/
data phase1;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
104 20 3 1 fever drg6 No
;
run;

data phase2;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
;
run;


libname old v9 'c:\temp\old';
data old.phase;
 set phase1;
 drop phase;
run;
libname new v9 'c:\temp\new';
data new.phase;
 set phase2;
 drop phase;
run;


%macro type_two(dsn=,subjid=,key=);
proc datasets library=work kill nolist nodetails;quit;
proc sort data=old.&amp;amp;dsn. out=old;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc sort data=new.&amp;amp;dsn. out=new;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc compare data=old compare=new noprint out=diff_&amp;amp;dsn.;
id &amp;amp;subjid. &amp;amp;key. ;
run;
data call_define(where=(upcase(vname) not in ("%upcase(&amp;amp;subjid.)"  "%upcase(&amp;amp;key.)" )));
 set diff_&amp;amp;dsn.(drop=_TYPE_ _OBS_  );
 length vname $ 40;
 array n{*} _numeric_;
 array c{*} _character_;
 do i=1 to dim(n);
   if n{i} not in (. 0) then do;vname=vname(n{i});output;end;
 end;
 do i=1 to dim(c);
   if findc(c{i},'X') then do;vname=vname(c{i});output;end;
 end;
keep &amp;amp;subjid. &amp;amp;key. vname;
run;
filename t temp;
data _null_;
 set call_define;
 file t;
 put "if &amp;amp;subjid.='" &amp;amp;subjid. "' and &amp;amp;key.='" &amp;amp;key. "' then call define('" vname "','style','style={background=red}');";
run;
data &amp;amp;dsn.;
if _n_=1 then do;
 if 0 then set new.&amp;amp;dsn.;
 if 0 then set old.&amp;amp;dsn.;
 declare hash h(dataset:"old.&amp;amp;dsn.");
 h.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h.definedone();

 declare hash h1(dataset:'call_define');
 h1.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h1.definedone();
end;
 set new.&amp;amp;dsn.;
 length new_change $ 40;
 if h.check() ne 0 then new_change='new' ;
 if h1.check() = 0 then new_change='change' ;
label new_change='new/change/delete';
run;
proc sql;
create table &amp;amp;dsn.2 as
select * from &amp;amp;dsn.
union
(select *,'delete' from old.&amp;amp;dsn. where &amp;amp;subjid. not in (select &amp;amp;subjid. from new.&amp;amp;dsn.));
quit;

ods excel file="c:\temp\want.xlsx" options(sheet_name="&amp;amp;dsn." autofilter='all' ) ;
proc report data=&amp;amp;dsn.2 split='*'  nowd;
column _all_ dummy;
define _all_/display;
define dummy/computed noprint;
compute dummy;
%include t;
if new_change='new' then call define(_row_,'style','style={background=verylightblue}');
if new_change='delete' then call define(_row_,'style','style={background=gold}');
endcomp;
run;
ods excel close;
%mend;

%type_two(dsn=phase,subjid=pid ,key=visit )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1686137558535.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84766i28D0F5EC21C78917/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1686137558535.png" alt="Ksharp_0-1686137558535.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 11:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879513#M347455</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-06-07T11:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879581#M347489</link>
      <description>Thank you so much sir &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 07 Jun 2023 14:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879581#M347489</guid>
      <dc:creator>possible</dc:creator>
      <dc:date>2023-06-07T14:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879665#M347521</link>
      <description>&lt;P&gt;Thank you so much sir.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the trouble. I have one more question, With the above program we would be able to get the subject only if the subject has one&amp;nbsp;occurrence right?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scenario that the subject has multiple occurrence in the source file like 5 time and in the target couple of record are deleted. So, I tried adding a variable to the where cause for teh select statement but i think its not working. i have multiple datapoint with same variable value.&amp;nbsp; How can filter the deleted record if the multiple variable are same. Based on my scenario, updated few data point below. Can you please review.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data phase1;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
104 20 3 1 fever drg6 No
104 20 3 1 headache drg1 No
104 20 3 1 pain drg3 yes
104 23 3 1 headache drg3 yes
104 20 2 1 pain drg5 No
104 20 4 1 pain drg1 No
104 43 1 1 vomit drg4 Yes
104 23 5 1 headache drg1 No
;
run;

data phase2;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
104 20 3 1 fever drg6 No
104 20 3 1 headache drg1 No
104 20 2 1 pain drg5 No
;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 21:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879665#M347521</guid>
      <dc:creator>possible</dc:creator>
      <dc:date>2023-06-07T21:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879736#M347553</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
" we would be able to get the subject only if the subject has one occurrence right? "
That is not true. My code would pick up all the subject's obs if it is not in OLD dataset.

If you  want include VISIT variable too ,try the following code.

NOTE: SUBJID= and KEY= identity a unique obs.
      You cann't have two obs have the same PID and same VISIT

Therefore,I modify your data to conform this rule.
*/

data phase1;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 1 asthma parace Yes
102 32 1 1 asthma sinarest Yes
101 23 2 1 headache drg1 No
103 43 1 1 vomit drg4 Yes
103 43 2 1 pain drg5 No
103 43 3 1 pain drg5 Yes
104 20 6 1 fever drg6 No
104 20 7 1 headache drg1 No
104 20 8 1 pain drg3 yes
104 23 3 1 headache drg3 yes
104 20 2 1 pain drg5 No
104 20 4 1 pain drg1 No
104 43 1 1 vomit drg4 Yes
104 23 5 1 headache drg1 No
;
run;

data phase2;
input PID AGE Visit phase event $ drug $ study $;
cards;
101 23 1 2 asthma parace Yes
102 32 1 2 asthma . Yes
101 23 2 2 acidity drg1 No
103 43 1 2 vomit drg4 Yes
103 43 2 2 pain drg5 No
103 43 4 2 pan drg5 Yes
107 43 3 2 pain drg5 Yes
104 20 1 1 fever drg6 No
104 20 3 1 headache drg1 No
104 20 2 1 pain drg5 No
;
run;


libname old v9 'c:\temp\old';
data old.phase;
 set phase1;
 drop phase;
run;
libname new v9 'c:\temp\new';
data new.phase;
 set phase2;
 drop phase;
run;


%macro type_two(dsn=,subjid=,key=);
proc datasets library=work kill nolist nodetails;quit;
proc sort data=old.&amp;amp;dsn. out=old;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc sort data=new.&amp;amp;dsn. out=new;by  &amp;amp;subjid. &amp;amp;key. ;run;
proc compare data=old compare=new noprint out=diff_&amp;amp;dsn.;
id &amp;amp;subjid. &amp;amp;key. ;
run;
data call_define(where=(upcase(vname) not in ("%upcase(&amp;amp;subjid.)"  "%upcase(&amp;amp;key.)" )));
 set diff_&amp;amp;dsn.(drop=_TYPE_ _OBS_  );
 length vname $ 40;
 array n{*} _numeric_;
 array c{*} _character_;
 do i=1 to dim(n);
   if n{i} not in (. 0) then do;vname=vname(n{i});output;end;
 end;
 do i=1 to dim(c);
   if findc(c{i},'X') then do;vname=vname(c{i});output;end;
 end;
keep &amp;amp;subjid. &amp;amp;key. vname;
run;
filename t temp;
data _null_;
 set call_define;
 file t;
 put "if &amp;amp;subjid.='" &amp;amp;subjid. "' and &amp;amp;key.='" &amp;amp;key. "' then call define('" vname "','style','style={background=red}');";
run;
data &amp;amp;dsn.;
if _n_=1 then do;
 if 0 then set new.&amp;amp;dsn.;
 if 0 then set old.&amp;amp;dsn.;
 declare hash h(dataset:"old.&amp;amp;dsn.");
 h.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h.definedone();

 declare hash h1(dataset:'call_define');
 h1.definekey("&amp;amp;subjid.","&amp;amp;key.");
 h1.definedone();
end;
 set new.&amp;amp;dsn.;
 length new_change $ 40;
 if h.check() ne 0 then new_change='new' ;
 if h1.check() = 0 then new_change='change' ;
label new_change='new/change/delete';
run;
proc sql;
create table &amp;amp;dsn.2 as
select * from &amp;amp;dsn.
union
(select *,'delete' from old.&amp;amp;dsn. where catx('|',&amp;amp;subjid.,&amp;amp;key.) not in (select catx('|',&amp;amp;subjid.,&amp;amp;key.) from new.&amp;amp;dsn.));
quit;

ods excel file="c:\temp\want.xlsx" options(sheet_name="&amp;amp;dsn." autofilter='all' ) ;
proc report data=&amp;amp;dsn.2 split='*'  nowd;
column _all_ dummy;
define _all_/display;
define dummy/computed noprint;
compute dummy;
%include t;
if new_change='new' then call define(_row_,'style','style={background=verylightblue}');
if new_change='delete' then call define(_row_,'style','style={background=gold}');
endcomp;
run;
ods excel close;
%mend;

%type_two(dsn=phase,subjid=pid ,key=visit )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1686224634803.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84822i2C4C77A691ECFAAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1686224634803.png" alt="Ksharp_0-1686224634803.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 11:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879736#M347553</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-06-08T11:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: comparing all variable values between two datasets and high-light mismatch</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879830#M347580</link>
      <description>Thank you, sir for responding. In my scenario, one of the dataset is recurrence kind of log line/repeating section. So, the visit is repeating for few datapoint. So, I add the repeating section datapoint to the catx statement and was able to get generate the report. For other datasets, reach out to get a more stable data. thank you so much sir for helping me.</description>
      <pubDate>Thu, 08 Jun 2023 21:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-all-variable-values-between-two-datasets-and-high/m-p/879830#M347580</guid>
      <dc:creator>possible</dc:creator>
      <dc:date>2023-06-08T21:23:56Z</dc:date>
    </item>
  </channel>
</rss>

