<?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: Macro compare a list of char and numeric variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611727#M178349</link>
    <description>&lt;P&gt;welcome to the world of comparing differences.&amp;nbsp; Sometimes just using Proc compare works better for me that using a SQL statement for comparing.&amp;nbsp; Other times I use the X commands to do compares when I need to do that for SAS datasets I create a temporary text version of the SAS data and call FC for comparing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One suggestion would be to get the process to work without macros for comparing the character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then re-macro it after the process works for a few different type of compares. -- Steady as she goes --&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2019 20:32:04 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2019-12-13T20:32:04Z</dc:date>
    <item>
      <title>Macro compare a list of char and numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611716#M178341</link>
      <description>&lt;P&gt;Hello -I am attempting to compare a large number of numeric and character across multiple datasets. I have coded the numeric portion, but am looking for a way to include both character and numeric variables. In my code below, the &amp;amp;list includes only numeric variables. I imagine I could use a compare function for character, but I'm not sure on the best route to take. Here is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;FONT&gt;OPTIONS MPRINT SYMBOLGEN&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;%MACRO DO_ALL(dsin1, dsin2, LIST );&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&amp;nbsp;%LOCAL i VAR ;&lt;BR /&gt;&amp;nbsp;%DO i=1 %TO %SYSFUNC(COUNTW(&amp;amp;list,%str( )));&lt;BR /&gt;&amp;nbsp; %LET VAR=%SCAN(&amp;amp;LIST,&amp;amp;i,%str( ));&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE COMP_&amp;amp;VAR.&amp;nbsp;&lt;BR /&gt;AS SELECT DISTINCT&lt;BR /&gt;A.id,&lt;BR /&gt;A.&amp;amp;VAR AS &amp;amp;VAR._1,&lt;BR /&gt;B.&amp;amp;VAR AS &amp;amp;var._2,&lt;BR /&gt;(A.&amp;amp;VAR. - B.&amp;amp;VAR.) AS &amp;amp;VAR._DIFF&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;FROM&amp;nbsp; &amp;amp;dsin1.&amp;nbsp;&amp;nbsp;&amp;nbsp;A&lt;BR /&gt;INNER JOIN &amp;amp;dsin2.&amp;nbsp;&amp;nbsp;B&lt;BR /&gt;ON A.id=B.id;&lt;BR /&gt;QUIT; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CNT_&amp;amp;VAR&lt;BR /&gt;AS SELECT&lt;BR /&gt;"&amp;amp;VAR" AS VARIABLE,&lt;BR /&gt;COUNT(&amp;amp;VAR._DIFF) AS TOTAL&lt;BR /&gt;FROM COMP_&amp;amp;VAR.&lt;BR /&gt;where &amp;amp;VAR._DIFF NE 0 ;&lt;BR /&gt;QUIT; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;%end;&lt;BR /&gt;%mend do_all;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;/**1st datasets for compare **/&lt;BR /&gt;%do_all(base,compare,&lt;BR /&gt;numeric_var1 numeric_var2 numeric_var3 numeric_var4 numeric_var5&amp;nbsp; ) ;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;/**2nd datasets for compare **/&lt;BR /&gt;%do_all(base2,compare2,&lt;BR /&gt;numeric_var1 numeric_var2 numeric_var3 numeric_var4 numeric_var5&amp;nbsp; ) ;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;I would like to include something like this for the character variables and possibly use a compare(with maybe conditionals to subset the type??)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;&amp;nbsp;%do_all( base, compare, char1 char2 char3 char4&amp;nbsp;&amp;nbsp; ) ;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 19:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611716#M178341</guid>
      <dc:creator>ICE1511</dc:creator>
      <dc:date>2019-12-13T19:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro compare a list of char and numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611727#M178349</link>
      <description>&lt;P&gt;welcome to the world of comparing differences.&amp;nbsp; Sometimes just using Proc compare works better for me that using a SQL statement for comparing.&amp;nbsp; Other times I use the X commands to do compares when I need to do that for SAS datasets I create a temporary text version of the SAS data and call FC for comparing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One suggestion would be to get the process to work without macros for comparing the character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then re-macro it after the process works for a few different type of compares. -- Steady as she goes --&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 20:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611727#M178349</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-12-13T20:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro compare a list of char and numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611798#M178402</link>
      <description>&lt;P&gt;I would begin with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;case (when a.&amp;amp;var ne b.&amp;amp;var then cat(a.&amp;amp;var, '*' , b.&amp;amp;var else ' ') as &amp;amp;var._diff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There aren't a whole lot of rules when it comes to a character variable being different.&amp;nbsp; So this will capture the differences.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An important question to consider:&amp;nbsp; will there always be exactly 1 observation per ID in both data sets?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 14:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-compare-a-list-of-char-and-numeric-variables/m-p/611798#M178402</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-14T14:28:47Z</dc:date>
    </item>
  </channel>
</rss>

