<?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 Run SQL statements stored in a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36249#M7140</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the paper. I'm native to SQL so using it backwards, I learned more about SQL to SAS equivalents!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Oct 2011 12:49:19 GMT</pubDate>
    <dc:creator>Mishka1</dc:creator>
    <dc:date>2011-10-28T12:49:19Z</dc:date>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36242#M7133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have fully formed SQL Select statements stored in a variable. I want to run them and append the results of each to a common data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each SQL statement has the same fields it returns so they will be able to be appended.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can copy the SQL statement right out of the table and paste it into a proc sql statement and run it, but I can't get a do loop to run through each SQL statement and I have no idea how to get them to append to just one table without overwriting it each time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Though now I'm thinking that I do have the ability to change the Select statement to an append...if that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the SQLtable that I have and the ResultsTable I need. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SQLtable:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;QueryName | SQLStatement&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Qry1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; Select Field1, Field2 From cwork.trans Where Field2= blue&lt;/P&gt;&lt;P&gt;Qry2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; Select Field1, Field2 From cwork.trans Where Field2= red&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ResultsTable:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;QueryName | Field1 | Field2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Oct 2011 15:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36242#M7133</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-27T15:02:56Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36243#M7134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; call execute() looping over these "variables" might achieve what you need&lt;/P&gt;&lt;P&gt;something like&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style=": ; Courier New&amp;amp;quot: ; color: navy; font-size: 9pt; background: white; font-family: &amp;amp;quot;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; _n_ &lt;/SPAN&gt;&lt;STRONG style=": ; Courier New&amp;amp;quot: ; color: teal; font-size: 9pt; background: white; font-family: &amp;amp;quot;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;then&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; execute( &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;'&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;proc sql noprint ;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; call execute( &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;'&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;outer union&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt; &lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; end_of_data &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;then&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; execute( &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;'&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;; quit ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: purple; font-size: 9pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;stop&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; SQLtable &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;=end_of_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style=": ; Courier New&amp;amp;quot: ; color: black; background: white; font-size: 9pt; mso-spacerun: yes; font-family: &amp;amp;quot;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: blue; font-size: 9pt;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt; execute( &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;SQLstatement &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;&lt;SPAN style="mso-spacerun: yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="MsoNormal" style="line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"&gt;&lt;STRONG style=": ; Courier New&amp;amp;quot: ; color: navy; font-size: 9pt; background: white; font-family: &amp;amp;quot;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: &amp;amp;quot;Courier New&amp;amp;quot;; background: white; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV class="mcePaste" id="_mcePaste" style="position: absolute; width: 1px; height: 1px; overflow: hidden; top: 0px; left: -10000px;"&gt;﻿&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Oct 2011 15:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36243#M7134</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-10-27T15:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36244#M7135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can do what you want with something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*create some test data;&lt;/P&gt;&lt;P&gt;data trans;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class (rename=(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; height=Field1));&lt;/P&gt;&lt;P&gt;&amp;nbsp; length Field2 $4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Field2="red";&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Field2="blue";&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data SQLtable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat QueryName $5.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat SQLStatement $80.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input QueryName SQLStatement &amp;amp;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;Qry1&amp;nbsp;&amp;nbsp; Select Field1, Field2 From work.trans Where Field2= 'blue'&lt;/P&gt;&lt;P&gt;Qry2&amp;nbsp;&amp;nbsp; Select Field1, Field2 From work.trans Where Field2= 'red'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select substr(SQLStatement,1,7)||'"'||QueryName||&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; '" as QueryName,'||substr(SQLStatement,7)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; into :queries&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; separated by " outer union corresponding "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from SQLtable&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;queries.&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want an explanation of why that would work, search the following document for the word "append":&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/269-29.pdf"&gt;http://www2.sas.com/proceedings/sugi29/269-29.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Oct 2011 15:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36244#M7135</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-27T15:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36245#M7136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will need to do code generation.&amp;nbsp; &lt;/P&gt;&lt;P&gt;You can use a data step to write code to file and then INCLUDE it.&lt;/P&gt;&lt;P&gt;Or use CALL EXECUTE to stuff the code onto the stack.&lt;/P&gt;&lt;P&gt;Or write a macro and generate macro calls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is what query do you want to generate to get your result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would assume you want something like.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as &lt;/P&gt;&lt;P&gt;&amp;nbsp; select * from (select "qry1" as QueryName),(... select statement...) &lt;/P&gt;&lt;P&gt;union&lt;/P&gt;&lt;P&gt;&amp;nbsp; select * from (select "qry2" as QueryName),(... select statement...) &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Watch out that PROC SQL has a limit on the number of tables that can be referenced in one statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Oct 2011 17:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36245#M7136</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-27T17:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36246#M7137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This could be simpler if the canned queries incorporated the IDs, as in&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New; color: #0000ff;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;cards&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt;Select "Qry1" as QueryName, Field1, Field2 From work.trans Where Field2= 'blue'&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt;Select "Qry2" as QueryName, Field1, Field2 From work.trans Where Field2= 'red'&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, why not use RESET to manage the state of the PRINT/NOPRINT option so that only one SQL step is needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Oct 2011 22:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36246#M7137</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-10-27T22:16:19Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36247#M7138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I incorporated the QueryName into the select like you suggested. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 12:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36247#M7138</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-28T12:40:03Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36248#M7139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I am hitting that limit now. Thanks for the heads up.&lt;BR /&gt;"A maximum of 256 tables can be processed in a single Proc SQL statement"&lt;/P&gt;&lt;P&gt;I'll be posting another question on a work-around if I can't figure it out in the next few hours.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 12:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36248#M7139</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-28T12:41:37Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36249#M7140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the paper. I'm native to SQL so using it backwards, I learned more about SQL to SAS equivalents!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 12:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36249#M7140</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-28T12:49:19Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36250#M7141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the INSERT statement in SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table want as &amp;amp;query1;&lt;/P&gt;&lt;P&gt;insert into want &amp;amp;query2;&lt;/P&gt;&lt;P&gt;insert into want &amp;amp;query3;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could instead create views in SQL and then use a DATA step to combine them. DATA steps do not have the same limits.&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create view v001 as &amp;amp;query1;&lt;/P&gt;&lt;P&gt;create view v002 as &amp;amp;query2;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set v001 v002 .... ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 13:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36250#M7141</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-28T13:45:47Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36251#M7142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Tom, Thanks for the Insert suggestion. That seemed to be the work-around I needed.&lt;/P&gt;&lt;P&gt;I'm trying to append all the views now but am getting an error.&lt;/P&gt;&lt;P&gt;I have about 300 views so I've tried to create an array to call in the Set statement so I don't have to list them out but I get an error. Hopefully I'm making an easy mistake. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;_null_&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; LogicTable;&amp;nbsp; /* table that has the viewnames*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;CALL&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; SYMPUT(&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 10pt;"&gt;'ViewNames'&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;, ViewName); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;stop&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; Queued;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &amp;amp;ViewNames;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Error is with the semicolon after &amp;amp;ViewNames;&lt;/P&gt;&lt;P&gt;It says, &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;Line generated by the macro variable "VIEWNAMES".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'SAS Monospace'; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 18:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36251#M7142</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-28T18:32:56Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36252#M7143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see two problems with that.&amp;nbsp; &lt;/P&gt;&lt;P&gt;1) From the error message it looks like the variable ViewName in the table LogicTable is numeric and missing so CALL SYMPUT is setting macro variabel ViewNames to a dot to represent a missing value.&amp;nbsp; To see what the macro variable ViewNames received throw in a %PUT "&amp;amp;viewnames"; statement.&lt;/P&gt;&lt;P&gt;2) Unless the table LogicTable has only one observation you cannot use CALL SYMPUT to generate a list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To generate a list into a macro variable it is easiest to use PROC SQL.&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select viewname into :viewnames separated by ' ' from logictable;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that the separated by clause is critical or else PROC SQL will just give you the value from the first observation if selects.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 18:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36252#M7143</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-28T18:56:45Z</dc:date>
    </item>
    <item>
      <title>Run SQL statements stored in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36253#M7144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; YAY. That worked perfectly. Now when I merge them, I'm getting an error because some of the views are empty. I can post this as a separate question if you think it should be. I was thinking I could make each view into a data set but that seems like a lot of space for something that probably has a more elegant answer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Oct 2011 20:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-SQL-statements-stored-in-a-variable/m-p/36253#M7144</guid>
      <dc:creator>Mishka1</dc:creator>
      <dc:date>2011-10-28T20:33:53Z</dc:date>
    </item>
  </channel>
</rss>

