<?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: PROC SQL or DATA STEP union with list of var in &amp;quot;on&amp;quot; condition in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633214#M77861</link>
    <description>&lt;P&gt;Yes, a macro ought to work here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
proc sql;
    create table final as
     a.*,
     %do i=5 %to 1 %by -1; 
     aux&amp;amp;i..id_&amp;amp;i %if &amp;amp;i&amp;gt;1 %then %str(,);
     %end;
     from one as a 
      %do i=5 %to 1 %by -1;
         left join aux&amp;amp;i on
         %do j=1 %to &amp;amp;i;
             a.var&amp;amp;j=aux&amp;amp;j..var&amp;amp;j %if &amp;amp;j&amp;lt;&amp;amp;i %then %str(and);
          %end;
      %end;
    ;
quit;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Mar 2020 11:16:40 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-03-19T11:16:40Z</dc:date>
    <item>
      <title>PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633182#M77858</link>
      <description>&lt;P&gt;Hi sas user's,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do left join in proc sql and using macrovariables in on sentence?&lt;/P&gt;&lt;P&gt;I want to parametizer this code:&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;proc sql; 
create table final as
select a.*, b.id_5,c.id_4,d.id_3, e.id_2, f.id_1
from one as a 
left join aux5 as b 
on a.var1=b.var1 and a.var2=b.var2 and a.var3=b.var3 and a.var4=b.var4
		and a.var5=b.var5
left join aux4 as c
on a.var1=b.var1 and a.var2=b.var2 and a.var3=b.var3 and a.var4=b.var4
left join aux3 as d
on a.var1=b.var1 and a.var2=b.var2 and a.var3=b.var3 
left join aux2 as e
on a.var1=b.var1 and a.var2=b.var2
left join aux1 as f
on a.var1=b.var1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think i can create a list with macrovariables, something like that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_var = var1 var2 var3 var4 var5;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But i don't know how to use it in on sentence of proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can use data step union too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone can help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 10:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633182#M77858</guid>
      <dc:creator>liguang01</dc:creator>
      <dc:date>2020-03-19T10:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633214#M77861</link>
      <description>&lt;P&gt;Yes, a macro ought to work here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
proc sql;
    create table final as
     a.*,
     %do i=5 %to 1 %by -1; 
     aux&amp;amp;i..id_&amp;amp;i %if &amp;amp;i&amp;gt;1 %then %str(,);
     %end;
     from one as a 
      %do i=5 %to 1 %by -1;
         left join aux&amp;amp;i on
         %do j=1 %to &amp;amp;i;
             a.var&amp;amp;j=aux&amp;amp;j..var&amp;amp;j %if &amp;amp;j&amp;lt;&amp;amp;i %then %str(and);
          %end;
      %end;
    ;
quit;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 11:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633214#M77861</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-19T11:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633278#M77865</link>
      <description>&lt;P&gt;I'm trying it, thanks about your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is my vars not always have same pattern then I was thinking about create a list and iterate it.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 13:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633278#M77865</guid>
      <dc:creator>liguang01</dc:creator>
      <dc:date>2020-03-19T13:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633279#M77866</link>
      <description>&lt;P&gt;Just loop over an INDEX into the list of names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var_list = var1 var2 var3 var4 var5;
%do index=1 %to %sysfunc(countw(&amp;amp;var_list,%str( )));
  %let var=%scan(&amp;amp;var_list,&amp;amp;index,%str( ));
  ....
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I leave it as an exercise how to generate the code you want using loop(s) like above.&lt;/P&gt;
&lt;P&gt;Hint: You don't have to use A B C as aliases, you can use alias like A1 A2 ...&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 13:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633279#M77866</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-19T13:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633280#M77867</link>
      <description>&lt;P&gt;Here how you can iterate over a list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo(list);
  %let i=1;
  %do %while(%scan(&amp;amp;list,&amp;amp;i) ne );
    %put %scan(&amp;amp;list,&amp;amp;i);
    %let i=%eval(&amp;amp;i+1);
  %end;
%mend;
%demo(var1 var2 var3 var4 var5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or a variation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo(list);
  %if &amp;amp;list ne %then 
    %do i=1 %to %sysfunc(countw(&amp;amp;list));
      %put %scan(&amp;amp;list,&amp;amp;i);
    %end;
%mend;
%demo(var1 var2 var3 var4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 13:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633280#M77867</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-19T13:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL or DATA STEP union with list of var in "on" condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633878#M77918</link>
      <description>&lt;P&gt;You could use the&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-function-to-create-an-quot-EquiJoin-quot-Condition/m-p/633871" target="_blank" rel="noopener"&gt;ut_sql_equijoin macro &lt;/A&gt;&amp;nbsp;that I posted to generate the conditions and potentially&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-function-to-return-a-list-of-variables-in-a-table-in-a/m-p/633536" target="_blank" rel="noopener"&gt;%ut_varlist&lt;/A&gt;&amp;nbsp; to generate the select statements.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 21:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-or-DATA-STEP-union-with-list-of-var-in-quot-on-quot/m-p/633878#M77918</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-03-21T21:00:52Z</dc:date>
    </item>
  </channel>
</rss>

