<?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: Can you use parameters in a query? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3072#M981</link>
    <description>Makes sense to me!  Thank you so much for such a detailed explanation.  I'll put the knowledge gained to good use.&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much!</description>
    <pubDate>Wed, 16 May 2007 20:38:10 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-05-16T20:38:10Z</dc:date>
    <item>
      <title>Can you use parameters in a query?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3070#M979</link>
      <description>I know you parameters can be used in the WHERE and GROUP portions of a query, but am wondering:&lt;BR /&gt;
&lt;BR /&gt;
Can parameters be used in the "CREATE TABLE..." part of a query, like in the following piece of code:&lt;BR /&gt;
&lt;BR /&gt;
CREATE TABLE HFA987A AS SELECT&lt;BR /&gt;
     EMPLOYEE.CAMPUS FORMAT=$63.,&lt;BR /&gt;
     &amp;amp;requestingcollege AS REQUESTING_COLLEGE format=$4.,&lt;BR /&gt;
     EMPLOYEE.CAMPUS_DESC FORMAT=$255.,&lt;BR /&gt;
     EMPLOYEE.COLLEGE FORMAT=$63.,&lt;BR /&gt;
&lt;BR /&gt;
What I am trying to do is to incorporate my parameter data into my table being created.  If anyone has an idea or two on how to do this, I would really appreciate hearing from you.  Thanks in advance!</description>
      <pubDate>Wed, 16 May 2007 15:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3070#M979</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-05-16T15:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use parameters in a query?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3071#M980</link>
      <description>Hi... I would test it out this way:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let myparm = ABCD&lt;BR /&gt;
%let mynum = 15;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table new as&lt;BR /&gt;
  select name,&lt;BR /&gt;
            "&amp;amp;myparm" as requesting_college format=$4.,&lt;BR /&gt;
             &amp;amp;mynum as anumber,&lt;BR /&gt;
            age, height&lt;BR /&gt;
  from sashelp.class;&lt;BR /&gt;
quit;&lt;BR /&gt;
 &lt;BR /&gt;
proc print data=new;&lt;BR /&gt;
title 'should have 2 new columns, one char and one numeric';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The bottom line is that you have to understand how macro variables work "outside" of being a parameter and then once you are dealing with parameters, you don't have any issues.&lt;BR /&gt;
    &lt;BR /&gt;
The difference in my code is that &amp;amp;myparm and &amp;amp;mynum are both assigned in the %let statement without any quotes -- this gives me the most flexibility to use them in subsequent code.&lt;BR /&gt;
   &lt;BR /&gt;
In "vanilla" PROC SQL code, IF I want to assign the constant value "ABCD" to the requesting_college variable and the number 10 to the anumber variable, then the code would be:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table new as&lt;BR /&gt;
  select name,&lt;BR /&gt;
            "ABCD" as requesting_college format=$4.,&lt;BR /&gt;
             10 as anumber,&lt;BR /&gt;
            age, height&lt;BR /&gt;
  from sashelp.class;&lt;BR /&gt;
quit;&lt;BR /&gt;
 [/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The quotes belong to the assignment of the character constant ABCD, so I need to have quotes around the &amp;amp;myparm reference (as shown in the first code example). But, the assignment for the anumber variable does NOT need quotes because I am creating a numeric constant for each row, so &amp;amp;mynum reference does NOT have quotes in the query code.&lt;BR /&gt;
 &lt;BR /&gt;
Essentially the SAS Macro facility is only generating code. So when the reference "&amp;amp;myparm" is encountered, the quotes belong to the syntax of the select statement and &amp;amp;myparm is passed to the macro processor to be resolved. If you put the reference to &amp;amp;myparm in single quotes, you will prevent the macro processor from resolving the macro reference. So you should always use double quotes where you need them.&lt;BR /&gt;
 &lt;BR /&gt;
fun macro tricks:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro hello;&lt;BR /&gt;
  %global parm;&lt;BR /&gt;
  %put hello &amp;amp;parm;&lt;BR /&gt;
   title "Hello &amp;amp;parm";&lt;BR /&gt;
   title2 'Hello &amp;amp;parm';&lt;BR /&gt;
   proc print data=sashelp.class;&lt;BR /&gt;
   run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
 &lt;BR /&gt;
%let parm=world;&lt;BR /&gt;
%hello;&lt;BR /&gt;
 &lt;BR /&gt;
%let parm=boys and girls, it is Howdy Doody time.;&lt;BR /&gt;
%hello;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
A neat debugging trick is to use the %put to write macro variables out to the SAS log. If you run this little snippet of code in a code node window, you should see that the macro variable reference in the single quotes was NOT resolved, but the macro variable reference in double quotes was resolved.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 16 May 2007 20:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3071#M980</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-05-16T20:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use parameters in a query?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3072#M981</link>
      <description>Makes sense to me!  Thank you so much for such a detailed explanation.  I'll put the knowledge gained to good use.&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much!</description>
      <pubDate>Wed, 16 May 2007 20:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Can-you-use-parameters-in-a-query/m-p/3072#M981</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-05-16T20:38:10Z</dc:date>
    </item>
  </channel>
</rss>

