<?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: Keeping variables in %let macro in select statement in PROC SQL? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696837#M212919</link>
    <description>&lt;P&gt;Use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the start of your program and run it again. Show us the LOG for this execution of the macro named %SQL_BEF. Please follow these instructions&amp;nbsp;&lt;EM&gt;exactly&lt;/EM&gt;. Copy the log as text and paste it here into the window that appears when you click on the &amp;lt;/&amp;gt; icon. DO NOT SKIP THIS STEP. Also, show us the complete log &lt;EM&gt;with nothing chopped out&lt;/EM&gt; for this entire macro execution portion of your program.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Nov 2020 12:30:14 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-11-05T12:30:14Z</dc:date>
    <item>
      <title>Keeping variables in %let macro in select statement in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696836#M212918</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope there is someone who can help me with this one:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple datasets called BEF201212, BEF201312, BEF201412 and etc. I do also have en external datafile which I have to join on my BEF201212 etc. tables. Therefore I have chosen a do loop in a Proc SQL procedure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to make a %let variable where the variables I want to keep from BEF201212 etc. is located. So next time I need the code with different variables I can just change the %let macro statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let BEF = B.PNR, B.FAMILIE_ID, B.OPR_LAND&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro sql_bef(start,end);&lt;/P&gt;&lt;P&gt;%do year = &amp;amp;start. %to &amp;amp;end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create tables test as&amp;nbsp;&lt;/P&gt;&lt;P&gt;select A.ID , &amp;amp;BEF.&amp;nbsp;&lt;/P&gt;&lt;P&gt;on A.ID = B.ID&lt;/P&gt;&lt;P&gt;order by ID;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%sql_bef(2012,2018)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the above macrocode my log tells me:&amp;nbsp;&lt;/P&gt;&lt;P&gt;"NOTE: Line generated by the macro variable "BEF".&amp;nbsp;&lt;/P&gt;&lt;P&gt;B.PNR, B.FAMILIE_ID, B.OPR_LAND GOPTIONS NOACCESIBLE&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I define my select variables in a macro?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards Frank&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 12:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696836#M212918</guid>
      <dc:creator>Kjeldsen89</dc:creator>
      <dc:date>2020-11-05T12:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables in %let macro in select statement in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696837#M212919</link>
      <description>&lt;P&gt;Use the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;at the start of your program and run it again. Show us the LOG for this execution of the macro named %SQL_BEF. Please follow these instructions&amp;nbsp;&lt;EM&gt;exactly&lt;/EM&gt;. Copy the log as text and paste it here into the window that appears when you click on the &amp;lt;/&amp;gt; icon. DO NOT SKIP THIS STEP. Also, show us the complete log &lt;EM&gt;with nothing chopped out&lt;/EM&gt; for this entire macro execution portion of your program.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 12:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696837#M212919</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-05T12:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables in %let macro in select statement in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696839#M212920</link>
      <description>&lt;P&gt;Also, the code you present is missing a semi-colon, make sure you fix that.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 12:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696839#M212920</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-05T12:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping variables in %let macro in select statement in PROC SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696854#M212929</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let BEF = B.PNR, B.FAMILIE_ID, B.OPR_LAND /* missing semicolon */

%macro sql_bef(start,end);
%do year = &amp;amp;start. %to &amp;amp;end. /* missing semicolon */
proc sql;
create tables test as 
select A.ID , &amp;amp;BEF. 
on A.ID = B.ID /* missing from and join clause */
order by ID;
quit;
%end;
%mend;
%sql_bef(2012,2018)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Given the multiple serious syntax mistakes in this code piece, I&amp;nbsp;&lt;STRONG&gt;STRONGLY&lt;/STRONG&gt; suggest you start with non-macro code first and get it to run without ANY ERRORs, WARNINGs or extraneous NOTEs. Only when that goal has been reached, you can start to make the code dynamic.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Nov 2020 13:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-variables-in-let-macro-in-select-statement-in-PROC-SQL/m-p/696854#M212929</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-05T13:01:22Z</dc:date>
    </item>
  </channel>
</rss>

