<?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 Union using Proc SQL - Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334386#M75508</link>
    <description>&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;&lt;BR /&gt;****************************************&lt;STRONG&gt;Example&lt;/STRONG&gt;*****************************************************&lt;BR /&gt;&lt;BR /&gt;%macro import_loop;
%let outobs=max;
%do i1=0  %to 24;
%let i = %sysfunc( putn(&amp;amp;i1,z2.));
proc import 			out  		= testv1_&amp;amp;i 
    					datafile 	= '/TESTING/DVR/DVR_V1_PROD_01182017.xls'
    					dbms 		= xls ;
    					sheet		="M&amp;amp;i._ACCT_BAL_AM";
    					getnames 	= yes;
run;
proc sql outobs=&amp;amp;outobs;
create table M&amp;amp;i._ACCT_BALANCE_AM
as
select  "M_ACCT_BAL_AM_&amp;amp;i." as  M_ACCT_BAL_AM_&amp;amp;i.
	   ,a.*
FROM testv1_&amp;amp;i  a
;

%end;
%mend import_loop;
%import_loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hi Team,&lt;BR /&gt;&lt;BR /&gt;Somone of you have you ever used **Union with Proc SQL** using macrovariables??&lt;BR /&gt;&lt;BR /&gt;With the macro shown &amp;nbsp;above I created 25 tables.&lt;BR /&gt;I want to create in the last step only &lt;STRONG&gt;one table which contains 25 tables&lt;BR /&gt;previously created using **Union of Proc SQL with macrovariables**&lt;/STRONG&gt;..&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;How can I do it using Macrovariables in a simple way similar that I created the 25 tables??&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Feb 2017 17:15:14 GMT</pubDate>
    <dc:creator>Jcorti</dc:creator>
    <dc:date>2017-02-20T17:15:14Z</dc:date>
    <item>
      <title>Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334386#M75508</link>
      <description>&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;&lt;BR /&gt;****************************************&lt;STRONG&gt;Example&lt;/STRONG&gt;*****************************************************&lt;BR /&gt;&lt;BR /&gt;%macro import_loop;
%let outobs=max;
%do i1=0  %to 24;
%let i = %sysfunc( putn(&amp;amp;i1,z2.));
proc import 			out  		= testv1_&amp;amp;i 
    					datafile 	= '/TESTING/DVR/DVR_V1_PROD_01182017.xls'
    					dbms 		= xls ;
    					sheet		="M&amp;amp;i._ACCT_BAL_AM";
    					getnames 	= yes;
run;
proc sql outobs=&amp;amp;outobs;
create table M&amp;amp;i._ACCT_BALANCE_AM
as
select  "M_ACCT_BAL_AM_&amp;amp;i." as  M_ACCT_BAL_AM_&amp;amp;i.
	   ,a.*
FROM testv1_&amp;amp;i  a
;

%end;
%mend import_loop;
%import_loop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Hi Team,&lt;BR /&gt;&lt;BR /&gt;Somone of you have you ever used **Union with Proc SQL** using macrovariables??&lt;BR /&gt;&lt;BR /&gt;With the macro shown &amp;nbsp;above I created 25 tables.&lt;BR /&gt;I want to create in the last step only &lt;STRONG&gt;one table which contains 25 tables&lt;BR /&gt;previously created using **Union of Proc SQL with macrovariables**&lt;/STRONG&gt;..&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;How can I do it using Macrovariables in a simple way similar that I created the 25 tables??&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 17:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334386#M75508</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-20T17:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334388#M75509</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not using PROC APPEND?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_loop;

proc datasets lib=WORK nolist;
     delete M_ALL;
quit; * delete first;

%let outobs=max;
%do i1=0  %to 24;
%let i = %sysfunc( putn(&amp;amp;i1,z2.));
proc import 			out  		= testv1_&amp;amp;i 
    					datafile 	= '/TESTING/DVR/DVR_V1_PROD_01182017.xls'
    					dbms 		= xls ;
    					sheet		="M&amp;amp;i._ACCT_BAL_AM";
    					getnames 	= yes;
run;
proc sql outobs=&amp;amp;outobs;
create table M&amp;amp;i._ACCT_BALANCE_AM
as
select  "M_ACCT_BAL_AM_&amp;amp;i." as  M_ACCT_BAL_AM_&amp;amp;i.
	   ,a.*
FROM testv1_&amp;amp;i  a
;

proc append base=M_ALL data=M&amp;amp;i._ACCT_BALANCE_AM force;
run; * append;

%end;
%mend import_loop;
%import_loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 17:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334388#M75509</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-20T17:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334396#M75514</link>
      <description>&lt;P&gt;Use a dataset list within a set statement to read all datasets and option indsname to get their names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_loop;
%do i1=0  %to 24;
	%let i = %sysfunc( putn(&amp;amp;i1,z2.));
	proc import  
							out  		= testv1_&amp;amp;i 
							datafile 	= '/TESTING/DVR/DVR_V1_PROD_01182017.xls'
							dbms 		= xls ;
							sheet		="M&amp;amp;i._ACCT_BAL_AM";
							getnames 	= yes;
	run;
%end;

data allMyData;
length fromSheet $32;
set testv1_: indsname=name;
fromSheet = cats("M", scan(name, 3, "._"), "_ACCT_BAL_AM");
run;

%mend import_loop;

%import_loop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2017 17:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334396#M75514</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-02-20T17:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334413#M75518</link>
      <description>&lt;P&gt;Thanks Man!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Actually was not needed proc sql I removed that part;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Could you please explain me what those statements do?&lt;/STRONG&gt;&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;set testv1_: indsname=name;
fromSheet = cats("M", scan(name, 3, "._"), "_ACCT_BAL_AM");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My guessing is the new variable **fromsheet" is selecting all variables that contains **_ACCT_BAL_AM**&lt;/P&gt;&lt;P&gt;When I am creating &amp;nbsp;**fromSheet variable** can I include in addition of&amp;nbsp;&lt;SPAN&gt;_ACCT_BAL_AM another variables??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am asking because in my excel file&amp;nbsp;DVR_V1_PROD_01182017 has more variables like &amp;nbsp;**M&amp;amp;i._ACT_PYMT_AMT**&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks a lot,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 18:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334413#M75518</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-20T18:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334416#M75519</link>
      <description>&lt;P&gt;Thanks a lot man for your replay&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 18:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334416#M75519</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-20T18:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334440#M75526</link>
      <description>&lt;P&gt;&lt;STRONG&gt;set testv1_:&lt;/STRONG&gt; reads all datasets in the WORK library with names starting with &lt;EM&gt;testv1_&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;indsname=name&lt;/STRONG&gt; creates a variable named &lt;EM&gt;name&lt;/EM&gt; that will be assigned the name of the dataset being read (eg "WORK.TESTV1_04")&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;scan(name, 3, "._"&lt;/STRONG&gt;) extracts the number from the dataset name (eg "04")&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;cats("M", scan(name, 3, "._"), "_ACCT_BAL_AM")&lt;/STRONG&gt; rebuilds the Excel sheet name (eg "M04&lt;SPAN&gt;_ACCT_BAL_AM&lt;/SPAN&gt;")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 19:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334440#M75526</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-02-20T19:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334470#M75534</link>
      <description>&lt;P&gt;Thanks a lot for easy explanation!!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 21:26:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334470#M75534</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-20T21:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Proc SQL - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334798#M75637</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Do you know if I can reference more variables here??&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Asking because I need to cosolidate &amp;nbsp;into:&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;data allMyData;
length fromSheet $32;
set testv1_: indsname=name;
fromSheet = cats("M", scan(name, 3, "._"), "_ACCT_BAL_AM");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;more macrovariables highlighted in black below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;%do i1=0  %to 24;
%let i = %sysfunc(putn(&amp;amp;i1,z2.));
%let cons=consolidated;

%let var1=M&amp;amp;i._ACCT_BALANCE_AM;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let var2=M&amp;amp;i._ACCT_CREDIT_LIMIT_AM;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;%let var3=M&amp;amp;i._ACTUAL_PYMT_AM;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let var4=M&amp;amp;i._ACCT_PAYMENT_AM;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JC&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 22:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Proc-SQL-Macro-Variables/m-p/334798#M75637</guid>
      <dc:creator>Jcorti</dc:creator>
      <dc:date>2017-02-21T22:35:58Z</dc:date>
    </item>
  </channel>
</rss>

