<?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 column in two datasets and output count in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184023#M46795</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are confused about what a macro is.&amp;nbsp; SAS macro language is a tool to generate code.&amp;nbsp; In general you cannot treat a macro as if it was a subroutine function.&lt;/P&gt;&lt;P&gt;Here is an example of how you might modify your macro to allow the user to specify the macro variable that you want it use to return the counts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; CompareUniqueCols(data1, data2, var, mvar=x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%local&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; noCompareObs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;...&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;mvar=&amp;amp;noCompareObs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; x=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;CompareUniqueCols&lt;/EM&gt;&lt;/STRONG&gt;(data1=today,date2=yesterday,var=CustomerID, mvar=X);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; Result = &amp;amp;x ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Apr 2014 12:41:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-04-18T12:41:03Z</dc:date>
    <item>
      <title>compare column in two datasets and output count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184020#M46792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to compare two datasets data1 and data2.&lt;/P&gt;&lt;P&gt;I have the column name in both "var"&lt;/P&gt;&lt;P&gt;and would like to check if there any differences in those two columns in the two datasets&lt;/P&gt;&lt;P&gt;and then count the number of differences&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then would like to call this macro function and save the count to macro variable x&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Somehow this doesnt work any help is appreciated. Thanks!ee&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro CompareUniqueCols(data1, data2, var);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %* check if all the unique values&amp;nbsp; in a column var of data set 1 and data set 2 are same and outputs the number of differences;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt; create table temp1 as select distinct &amp;amp;var&amp;nbsp; from &amp;amp;data1 order by &amp;amp;var;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table temp2 as select distinct &amp;amp;var from &amp;amp;data2 order by &amp;amp;var;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc compare base = temp2 compare = temp1 outall outnoequal out = outcompare ; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select count(*) into: noCompareObs from outcompare ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;noCompareObs;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %let x = %CompareUniqueCols(data1, data2, var); &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 18:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184020#M46792</guid>
      <dc:creator>hdg</dc:creator>
      <dc:date>2014-04-17T18:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: compare column in two datasets and output count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184021#M46793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you looked at PROC COMPARE&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 07:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184021#M46793</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-04-18T07:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: compare column in two datasets and output count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184022#M46794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming the datasets have only one variable "Var" . Here's the data step way ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; DIFF&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;MERGE&lt;/P&gt;&lt;P&gt; DATA1(IN = A)&lt;/P&gt;&lt;P&gt;DATA2(IN = B)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;BY VAR ;&lt;/P&gt;&lt;P&gt;IF A AND B THEN DELETE ;&lt;/P&gt;&lt;P&gt;ELSE OUTPUT ;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;you can get the count using your SQL on DIFF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 12:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184022#M46794</guid>
      <dc:creator>Karthikeyan</dc:creator>
      <dc:date>2014-04-18T12:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: compare column in two datasets and output count</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184023#M46795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are confused about what a macro is.&amp;nbsp; SAS macro language is a tool to generate code.&amp;nbsp; In general you cannot treat a macro as if it was a subroutine function.&lt;/P&gt;&lt;P&gt;Here is an example of how you might modify your macro to allow the user to specify the macro variable that you want it use to return the counts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; CompareUniqueCols(data1, data2, var, mvar=x);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%local&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; noCompareObs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;...&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;mvar=&amp;amp;noCompareObs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; x=;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;%&lt;STRONG&gt;&lt;EM&gt;CompareUniqueCols&lt;/EM&gt;&lt;/STRONG&gt;(data1=today,date2=yesterday,var=CustomerID, mvar=X);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%put&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; Result = &amp;amp;x ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 12:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compare-column-in-two-datasets-and-output-count/m-p/184023#M46795</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-04-18T12:41:03Z</dc:date>
    </item>
  </channel>
</rss>

