<?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: Difference between Two dataset variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335279#M75868</link>
    <description>&lt;P&gt;Proc compare can do that for you without any complicated coding. Check the outnoequal, outdif, outbase and outcompare&amp;nbsp;options out:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1f136xdchlfrtn1663tmzklctb6.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1f136xdchlfrtn1663tmzklctb6.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Feb 2017 14:24:58 GMT</pubDate>
    <dc:creator>nehalsanghvi</dc:creator>
    <dc:date>2017-02-23T14:24:58Z</dc:date>
    <item>
      <title>Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334757#M75613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have requirement to compare two monthly extracts which has same varibales, but values may be changed between two datasets. I need to extract an observation that has different value in nay variable compare to&amp;nbsp;last month dataset. For example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;DATA SasConf;
INFILE DATALINES;
INPUT
ID
ConfName $
ConfYear
ConfCity $
ConfST $ ;
DATALINES4;
1 SUGI 2006 San Francisco CA
2 PHARMASUG 2006 Bonita Springs FL
3 NESUG 2006 newyork NY
4 WUSS 2006 Irvine CA
5 SESUG 2006 Atlanta GA
6 SCSUG 2006 Irving TX
7 MWSUG 2006 Dearborn MI
8 SUGI 2007 Orlando FL
;;;;
&amp;nbsp;
DATA SasConf2;
INFILE DATALINES;
INPUT&amp;nbsp; ID
ConfName $
ConfYear
ConfCity $
ConfST $ ;
DATALINES4;
&amp;nbsp;1 SUGI 2006 San Francisco CA
2 PHARMASUG 2006 Bonita Springs FL
3 NESUG 2006 Philadelphia PA
4 WUSS 2006 Irvine CA
5 SESUG 2006 Atlanta GA
6 SCSUG 2006 Irving TX
7 PNWSUG 2006 Seaside OR
8 NESUGI 2007 Orlando FL
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compare these two datasets and the output datset should have following obervations:&lt;/P&gt;
&lt;P&gt;3 NESUG 2006 Philadelphia PA&lt;/P&gt;
&lt;P&gt;8 NESUGI 2007 Orlando FL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: there is&amp;nbsp;primary key (ID)&amp;nbsp;in the dataset, so any variable value&amp;nbsp;can be different, so need to select the observation which is changed from the&amp;nbsp;last month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;is the way that we can do this on the data step (don’t want to use proc compare).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for all your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 20:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334757#M75613</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2017-02-21T20:47:24Z</dc:date>
    </item>
    <item>
      <title>Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334754#M75615</link>
      <description>&lt;P&gt;&lt;SPAN class="DateTime lia-message-posted-on lia-component-common-widget-date"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have requirement to compare two monthly extracts which has same varibales, but values may be changed between two datasets. I need to extract observations that has different value in nay varibale compare to&amp;nbsp;last month dataset. For example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SasConf;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INFILE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DATALINES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INPUT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ConfName $&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;ConfYear&lt;/P&gt;&lt;P&gt;ConfCity $&lt;/P&gt;&lt;P&gt;ConfST $ ;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DATALINES4&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 SUGI 2006 San Francisco CA&lt;/P&gt;&lt;P&gt;2 PHARMASUG 2006 Bonita Springs FL&lt;/P&gt;&lt;P&gt;3 NESUG 2006 newyork NY&lt;/P&gt;&lt;P&gt;4 WUSS 2006 Irvine CA&lt;/P&gt;&lt;P&gt;5 SESUG 2006 Atlanta GA&lt;/P&gt;&lt;P&gt;6 SCSUG 2006 Irving TX&lt;/P&gt;&lt;P&gt;7 MWSUG 2006 Dearborn MI&lt;/P&gt;&lt;P&gt;8 SUGI 2007 Orlando FL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DATA&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; SasConf2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INFILE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DATALINES&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; ID&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;ConfName $&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;ConfYear&lt;/P&gt;&lt;P&gt;ConfCity $&lt;/P&gt;&lt;P&gt;ConfST $ ;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DATALINES4&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 SUGI 2006 San Francisco CA&lt;/P&gt;&lt;P&gt;2 PHARMASUG 2006 Bonita Springs FL&lt;/P&gt;&lt;P&gt;3 NESUG 2006 Philadelphia PA&lt;/P&gt;&lt;P&gt;4 WUSS 2006 Irvine CA&lt;/P&gt;&lt;P&gt;5 SESUG 2006 Atlanta GA&lt;/P&gt;&lt;P&gt;6 SCSUG 2006 Irving TX&lt;/P&gt;&lt;P&gt;7 PNWSUG 2006 Seaside OR&lt;/P&gt;&lt;P&gt;8 NESUGI 2007 Orlando FL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Compare these two datasets and the output datset should have following obervations:&lt;/P&gt;&lt;P&gt;3 NESUG 2006 Philadelphia PA&lt;/P&gt;&lt;P&gt;8 NESUGI 2007 Orlando FL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: there is&amp;nbsp;primary key (ID)&amp;nbsp;in the dataset, so any varibale value&amp;nbsp;can be different, so need to select the observation which is changed from the&amp;nbsp;last month .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is the way that we can do this on the data step (dont want to use proc compare).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all your help.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Feb 2017 20:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334754#M75615</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2017-02-21T20:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334769#M75618</link>
      <description>&lt;P&gt;Your data read doesn't work correctly as two-word city names end up in different columns but the result you're looking for can be obtained with a proc compare like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare base=sasconf compare=sasconf2 out=comp noprint outcompare outnoequal;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 20:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334769#M75618</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-21T20:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334786#M75629</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
  select * from T2
  except
  select * from T1 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 21:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334786#M75629</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-02-21T21:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334846#M75654</link>
      <description>&lt;P&gt;A Data Step Approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each ID, concatenate all variables into a LIST, for this purpose, confYear can &amp;nbsp;be read as a string. Do this with one data set. Then read the other data set and make a concatenated LIST for each observation. For the given ID, check the LIST obtained in the previous data set. If the two are not equal, then output the record. I use a string array to hold the LIST, the array is referenced by the ID as Index of the array.&lt;/P&gt;&lt;P&gt;The progam can me made dynamic by getting the number of IDs and the total string-lengths of all variables prior to the data step and fill these in the appropriate statements.&lt;/P&gt;&lt;P&gt;I am getting records 3, 7 and 8 against the reported 3 and 8. If I have missed something, let me know.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SasConf;
INFILE DATALINES;
INPUT ID ConfName :$9. ConfYear $4. ConfCity &amp;amp;$15. ConfST $ ;
DATALINES4;
1 SUGI 2006   San Francisco   CA
2 PHARMASUG 2006   Bonita Springs   FL
3 NESUG 2006   newyork    NY
4 WUSS 2006   Irvine    CA
5 SESUG 2006   Atlanta    GA
6 SCSUG 2006   Irving    TX
7 MWSUG 2006   Dearborn    MI
8 SUGI 2007   Orlando    FL
;;;;
run;


DATA SasConf2;
INFILE DATALINES;
INPUT  ID ConfName :$9. ConfYear $4. ConfCity &amp;amp;$15. ConfST $ ;
DATALINES4;
1 SUGI 2006 San Francisco   CA
2 PHARMASUG 2006 Bonita Springs   FL
3 NESUG 2006 Philadelphia   PA
4 WUSS 2006 Irvine   CA
5 SESUG 2006 Atlanta   GA
6 SCSUG 2006 Irving   TX
7 PNWSUG 2006 Seaside   OR
8 NESUGI 2007 Orlando   FL
;;;;
run;


data want;
	if _n_ = 1 then do;
		array k[8] $35 _temporary_ ;
		length list $35;
		do j = 1 by 1 until(eof);
			set sasconf2 end = eof;
			array vars ConfName -- ConfST;
			do i = 1 to dim(vars);
				call catx('|', list, trim(vars[i]));
			end;
			k[j] = list;
			call missing(list);
		end;
	end;
	set sasconf;
		call missing(list);
		do i = 1 to dim(vars);
			call catx('|', list, trim(vars[i]));
		end;
		if k[id] ^= list then output;
drop list i j;	
run;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2017 06:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/334846#M75654</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-02-22T06:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335073#M75763</link>
      <description>&lt;P&gt;Thank You ! This code works great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way that we can identify which variable values has changed in a row when compared to the last month dataset ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 18:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335073#M75763</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2017-02-22T18:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335187#M75828</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; k&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;^=&lt;/SPAN&gt; list &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Do you want the first mismatch or all mismatches? Well I will sketch the way to do it. You may try and be proud to have done it.&lt;/P&gt;&lt;P&gt;The above statement is the place you have to start with as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if k[id] ^= list then do;&lt;/P&gt;&lt;P&gt;*do your work here.&lt;/P&gt;&lt;P&gt;.......&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At present you have VAR[*], an array holding values for the the variables from one data set and K[ID] holds the combined list values for variables of the other data set. Using VAR[*], take each variable and see whether it matches in K[ID]. If it is not, then it is the first mismatched variable. If you need all unmatched, try with next variable from VAR[*] and on. You may use WHICHC() function for finding the match or no match.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 03:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335187#M75828</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-02-23T03:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between Two dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335279#M75868</link>
      <description>&lt;P&gt;Proc compare can do that for you without any complicated coding. Check the outnoequal, outdif, outbase and outcompare&amp;nbsp;options out:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1f136xdchlfrtn1663tmzklctb6.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1f136xdchlfrtn1663tmzklctb6.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2017 14:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-Two-dataset-variable-values/m-p/335279#M75868</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-23T14:24:58Z</dc:date>
    </item>
  </channel>
</rss>

