<?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: How to loop this proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109030#M30393</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or Call execute(). Why not try to use PROC COPY .it is a powerful tool to copy tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data _null_;
 set sashelp.vmember(keep=memname libname where=(libname='WORK')) end=last;
 if _n_ eq 1 then call execute('proc sql;');
 call execute('create table sqldb.A'||strip(memname)||' as select * from '||strip(memname)||' ;');
 if last then call execute('quit;');
run

&lt;/PRE&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;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jul 2012 02:35:28 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-07-17T02:35:28Z</dc:date>
    <item>
      <title>How to loop this proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109027#M30390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following Proc Sql to create sql tables, Instead of reapeating the commands I would like to know if I can use DO loop in proc SQL (all data in different years are available in the library)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.ACxC_1993 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from CxC1993; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AValuAdded_1993 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from ValuAdded1993; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AFinalDemand_1993 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from FinalDemand1993; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.ACxC_1994 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from CxC1994; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AValuAdded_1994 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from ValuAdded1994; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AFinalDemand_1994 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from FinalDemand1994; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.ACxC_1995 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from CxC1995; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AValuAdded_1995 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from ValuAdded1995; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table sqldb.AFinalDemand_1995 as &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from FinalDemand1995; &lt;/P&gt;&lt;P&gt;quit; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 20:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109027#M30390</guid>
      <dc:creator>goliPSU</dc:creator>
      <dc:date>2012-07-16T20:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop this proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109028#M30391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; One possible solution would be to use a SAS Macro program to create your repetitive code. Since the only thing that changes is the year suffix, you could use a macro variable, such as &amp;amp;YR as a placeholder, which would be resolved into a year value when the macro program was invoked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; This user group paper outlines the basics of using SAS Macro variables and SAS macro programs and will be helpful in getting you pointed in the right direction. In addition, there have been many, many previous forum postings on the use of Macro variables and Macro programs to generate code.&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" title="http://www2.sas.com/proceedings/sugi28/056-28.pdf"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.nesug.org/proceedings/nesug07/cc/cc41.pdf" title="http://www.nesug.org/proceedings/nesug07/cc/cc41.pdf"&gt;http://www.nesug.org/proceedings/nesug07/cc/cc41.pdf&lt;/A&gt; (look on page 2 at the PROC MEANS example)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; What you have to remember is that the SAS Macro Facility only exists to generate code. So the first thing you have to do is start with a working SAS program, then figure out where in your program you can use macro variables or macro %DO loops to generate repetitive code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; It looks like you have a good start with a working SAS program. Now you need to learn how to add macro variables and macro programs into the mix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 21:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109028#M30391</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-07-16T21:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop this proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109029#M30392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would be a lot easier if you weren't renaming the datasets.&amp;nbsp; Then you could just use PROC COPY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc copy in=work out=sqldb ;&lt;/P&gt;&lt;P&gt; select &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CxC1993&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;ValuAdded1993 &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;FinalDemand1993 ....&lt;/SPAN&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jul 2012 22:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109029#M30392</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-07-16T22:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop this proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109030#M30393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or Call execute(). Why not try to use PROC COPY .it is a powerful tool to copy tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data _null_;
 set sashelp.vmember(keep=memname libname where=(libname='WORK')) end=last;
 if _n_ eq 1 then call execute('proc sql;');
 call execute('create table sqldb.A'||strip(memname)||' as select * from '||strip(memname)||' ;');
 if last then call execute('quit;');
run

&lt;/PRE&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;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 02:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109030#M30393</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-07-17T02:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop this proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109031#M30394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all, it was very helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2012 14:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-loop-this-proc-SQL/m-p/109031#M30394</guid>
      <dc:creator>goliPSU</dc:creator>
      <dc:date>2012-07-17T14:03:44Z</dc:date>
    </item>
  </channel>
</rss>

