<?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 more then two macro values doesnt get resolved/passed correctly with quotation marks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932214#M366716</link>
    <description>thank you for your answer, but i dont want no other sql generated (and the query works), because there is some more logic behind that (to exclude this and that).&lt;BR /&gt;&lt;BR /&gt;So query has the whole sql i need and with&lt;BR /&gt;%let query = Select %scan(&amp;amp;name.,&amp;amp;i) as %scan(&amp;amp;name.,&amp;amp;i) into :tmp_result from maps.%scan(&amp;amp;table.,&amp;amp;i) where color = 'blue'; i got the warning tmp_results doenst get resolved.</description>
    <pubDate>Thu, 13 Jun 2024 16:27:36 GMT</pubDate>
    <dc:creator>Chados</dc:creator>
    <dc:date>2024-06-13T16:27:36Z</dc:date>
    <item>
      <title>PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932205#M366711</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i dont know how to proceed on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.test;&lt;/P&gt;&lt;P&gt;length result $100 conv $100;&lt;/P&gt;&lt;P&gt;result = "";&lt;/P&gt;&lt;P&gt;conv = "";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro run;&lt;/P&gt;&lt;P&gt;/* here i build some dynamic sql*/&lt;/P&gt;&lt;P&gt;%do i=1 %to 10;&lt;/P&gt;&lt;P&gt;%let query = Select %scan(&amp;amp;name.,&amp;amp;i) as&amp;nbsp; %scan(&amp;amp;name.,&amp;amp;i) from maps.%scan(&amp;amp;table.,&amp;amp;i) where color = 'blue';&lt;/P&gt;&lt;P&gt;%let tmp_name = %scan(&amp;amp;name,&amp;amp;i.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*and now the strange part*/&lt;/P&gt;&lt;P&gt;proc sql outobs=1;&lt;/P&gt;&lt;P&gt;insert into work.test (result,conv) values ("&amp;amp;query", "tmp_name");&lt;BR /&gt;/* so this work and i got as the result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;result&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;&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;&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;&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; conv&lt;/P&gt;&lt;P&gt;SELECT COMMENT1 from maps.XY where color ... &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; COMMENT1&lt;/P&gt;&lt;P&gt;SELECT Dell from maps.XY where and so on&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; DELL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i want the result from the dynamic sql, like:&lt;/P&gt;&lt;P&gt;result&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; conv&lt;/P&gt;&lt;P&gt;Santa Barb &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; COMMENT1&lt;/P&gt;&lt;P&gt;Sakassuro &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; DELL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With&lt;/P&gt;&lt;P&gt;proc sql outobs=1;&lt;/P&gt;&lt;P&gt;insert into work.test (result)&amp;nbsp; (&amp;amp;query);&lt;BR /&gt;i get the correct data:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;result&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;/P&gt;&lt;P&gt;Santa Barb &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sakassuro &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;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if i want to add some more columns, i need to add the quotation marks in combination with values and i cant get by that.&lt;BR /&gt;I have tried many options, even with a new dataset and so on, but i cant get it solved.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 15:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932205#M366711</guid>
      <dc:creator>Chados</dc:creator>
      <dc:date>2024-06-13T15:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932208#M366714</link>
      <description>&lt;P&gt;You are using the wrong SQL code.&amp;nbsp; VALUES() wants actual VALUES, not code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure to tell %SCAN() what character(s) it should use a the delimiter in your list of names.&amp;nbsp; Otherwise your code will have issues when you use VALIDVARNAME=ANY and the names include some of the other delimiter characters that %SCAN() uses by default when you don't specify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either run the SQL code and store the result into a macro variable so you can use it to generate the VALUES () clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let tmp_name = %scan(&amp;amp;name,&amp;amp;i,%str( ));
%let tmp_table = maps.%scan(&amp;amp;table,&amp;amp;i,%str( ));
proc sql noprint;
select quote(trim(&amp;amp;tmp_name),"'")
  into :tmp_result 
  from &amp;amp;tmp_table
  where color='blue'
;
insert into work.test (result,conv) values (&amp;amp;tmp_result, "&amp;amp;tmp_name");
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just use SELECT instead of VALUES.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
insert into work.test (result,conv) 
select &amp;amp;tmp_name,"&amp;amp;tmp_name"
  from &amp;amp;tmp_table
  where color='blue'
;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 16:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932208#M366714</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-13T16:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932214#M366716</link>
      <description>thank you for your answer, but i dont want no other sql generated (and the query works), because there is some more logic behind that (to exclude this and that).&lt;BR /&gt;&lt;BR /&gt;So query has the whole sql i need and with&lt;BR /&gt;%let query = Select %scan(&amp;amp;name.,&amp;amp;i) as %scan(&amp;amp;name.,&amp;amp;i) into :tmp_result from maps.%scan(&amp;amp;table.,&amp;amp;i) where color = 'blue'; i got the warning tmp_results doenst get resolved.</description>
      <pubDate>Thu, 13 Jun 2024 16:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932214#M366716</guid>
      <dc:creator>Chados</dc:creator>
      <dc:date>2024-06-13T16:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932216#M366718</link>
      <description>&lt;P&gt;A couple of coding style comments:&lt;/P&gt;
&lt;PRE&gt;%macro run;&lt;/PRE&gt;
&lt;P&gt;Since the call to this macro would be %run it is very easy to confuse with the keyword "run" that ends most procedures. More descriptive names are a very good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And more serious in terms of debugging or preventing problems&lt;/P&gt;
&lt;PRE&gt;%let query = Select %scan(&amp;amp;name.,&amp;amp;i) as  %scan(&amp;amp;name.,&amp;amp;i) from maps.%scan(&amp;amp;table.,&amp;amp;i) where color = 'blue';&lt;/PRE&gt;
&lt;P&gt;This one line uses two macro variables &amp;amp;name and &amp;amp;table without any idea of where they may be set. Just having macro variables appear that are not created in the macro or passed as parameters is a common cause of "that was working yesterday, why isn't it today?". And absolute bare minimum would be to have a comment as to where these macro variables are create. Better is to have them as actual parameters in the definition and call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 16:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932216#M366718</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-13T16:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932360#M366775</link>
      <description>&lt;P&gt;Please re-read my previous post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you made that macro variable you called QUERY did you actually as SAS to run it?&amp;nbsp; It not there is no way that SAS would know to put anything into the macro variable TMP_RESULT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show code that works WITHOUT ANY MACRO VARIABLES.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing to remember to do that I did not show in my code is to make sure that the macro variable gets created.&amp;nbsp; Which might not happen&amp;nbsp; if no observations satisfy the WHERE clause of the query.&amp;nbsp; The easiest way is to assign some default value before running the query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let query = 
select %scan(&amp;amp;name.,&amp;amp;i) as %scan(&amp;amp;name.,&amp;amp;i) into :tmp_result 
from maps.%scan(&amp;amp;table.,&amp;amp;i) 
where color = 'blue'
; 

proc sql noprint;
%let tmp_result= ;
&amp;amp;query;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 02:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932360#M366775</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-14T02:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL more then two macro values doesnt get resolved/passed correctly with quotation marks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932371#M366782</link>
      <description>&lt;P&gt;So you want to create code dynamically.&lt;/P&gt;
&lt;P&gt;First, post a non-macro example of the code you want to run for a single instance.&lt;/P&gt;
&lt;P&gt;Next, post the same code for another single instance, so we can see what changes between them.&lt;/P&gt;
&lt;P&gt;Third, post the data you have from which you want to develop the dynamic elements of that code.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 07:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-more-then-two-macro-values-doesnt-get-resolved-passed/m-p/932371#M366782</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-14T07:29:14Z</dc:date>
    </item>
  </channel>
</rss>

