<?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 Values in 2 Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824268#M325508</link>
    <description>&lt;P&gt;You apparently want the variable names that are common to both test1 and test2, right?&amp;nbsp; If so, don't bother to do that work in macro language.&amp;nbsp; Do it in SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input code1 $6. code2 $6. code3 $6.;
datalines;
80090 34521 63421
;

data test2;
input code1 $6. code2 $6. code3 $6. code4 $6.;
datalines;
23145 23147 52134 90843
;

proc sql noprint;
  create table test1_vars as select name
    from dictionary.columns
    where upcase(memname)= 'TEST1' And upcase(libname) = 'WORK';
  create table test2_vars as select name
    from dictionary.columns
    where upcase(memname)= 'TEST2' And upcase(libname) = 'WORK';

  select distinct name into :macro1 separated by ' '
    from test1_vars;
  select distinct name into :macro2 separated by ' '
    from test2_vars;
  select distinct name into :macro3 separated by ' '
   from (select name from test1_vars intersect select name from test2_vars)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, if you use &lt;EM&gt;&lt;STRONG&gt;SELECT DISTINCT&lt;/STRONG&gt;&lt;/EM&gt;, then &lt;EM&gt;&lt;STRONG&gt;ORDER BY&lt;/STRONG&gt;&lt;/EM&gt; the same variable is redundant.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2022 01:06:40 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-07-20T01:06:40Z</dc:date>
    <item>
      <title>Comparing Values in 2 Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824256#M325500</link>
      <description>&lt;P&gt;I have two macro variables, I would like to compare the two macro variables and return a third macro that only contains the values the other two have in common.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test1;
input code1 $6. code2 $6. code3 $6.;
datalines;
80090 34521 63421
;

data test2;
input code1 $6. code2 $6. code3 $6. code4 $6.;
datalines;
23145 23147 52134 90843
;

proc sql;
    select distinct name
    into :macro1 separated by " "
    from dictionary.columns
     where upcase(memname)= 'TEST1'
             And
             upcase(libname) = 'WORK'
     order by name
;
quit;

proc sql;
    select distinct name
    into :macro2 separated by " "
    from dictionary.columns
     where upcase(memname)= 'TEST2'
             And
             upcase(libname) = 'WORK'
     order by name
;
quit;

%put &amp;amp;macro1;
%put &amp;amp;macro2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to return a macro3 that would only contain code1 code2 code3. One macro will not always be a perfect subset of the other.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 22:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824256#M325500</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2022-07-19T22:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Values in 2 Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824258#M325502</link>
      <description>&lt;P&gt;Is your data originally in two tables? If so can you create the table 3 out of test1/test2 instead of the macro variable?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 23:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824258#M325502</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-19T23:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing Values in 2 Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824268#M325508</link>
      <description>&lt;P&gt;You apparently want the variable names that are common to both test1 and test2, right?&amp;nbsp; If so, don't bother to do that work in macro language.&amp;nbsp; Do it in SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input code1 $6. code2 $6. code3 $6.;
datalines;
80090 34521 63421
;

data test2;
input code1 $6. code2 $6. code3 $6. code4 $6.;
datalines;
23145 23147 52134 90843
;

proc sql noprint;
  create table test1_vars as select name
    from dictionary.columns
    where upcase(memname)= 'TEST1' And upcase(libname) = 'WORK';
  create table test2_vars as select name
    from dictionary.columns
    where upcase(memname)= 'TEST2' And upcase(libname) = 'WORK';

  select distinct name into :macro1 separated by ' '
    from test1_vars;
  select distinct name into :macro2 separated by ' '
    from test2_vars;
  select distinct name into :macro3 separated by ' '
   from (select name from test1_vars intersect select name from test2_vars)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, if you use &lt;EM&gt;&lt;STRONG&gt;SELECT DISTINCT&lt;/STRONG&gt;&lt;/EM&gt;, then &lt;EM&gt;&lt;STRONG&gt;ORDER BY&lt;/STRONG&gt;&lt;/EM&gt; the same variable is redundant.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2022 01:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-Values-in-2-Macro-Variables/m-p/824268#M325508</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-20T01:06:40Z</dc:date>
    </item>
  </channel>
</rss>

