<?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 inside MACRO in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638511#M189875</link>
    <description>&lt;P&gt;What are the values of &amp;amp;i and &amp;amp;j?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your question text uses: "predict_2_I&amp;amp;&amp;amp;J." which is indeed a &lt;STRONG&gt;very different &lt;/STRONG&gt;thing than "predict_2_&amp;amp;I&amp;amp;J&lt;/P&gt;
&lt;P&gt;If you actually have &amp;amp;&amp;amp;J when the macro processor sees two &amp;amp; it "holds" the first one then resolves &amp;amp;J. The "uses" the held &amp;amp; to resolve.&lt;/P&gt;
&lt;P&gt;So if &amp;amp;j is CAT then &amp;amp;&amp;amp;J =&amp;gt;&amp;amp;Cat. Which would thrown an error if you do not have a macro variable &amp;amp;Cat defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HInt: when you get an error copy the proc or data step code will all the notes and errors from the log and paste into a code box opened on the forum with the &amp;lt;/&amp;gt; icon. &lt;BR /&gt;The code box is important to keep the message windows from reformatting text and moving the diagnostic characters that frequently appear with error messages.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 21:49:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-08T21:49:19Z</dc:date>
    <item>
      <title>PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638504#M189870</link>
      <description>&lt;P&gt;Hi everyone, there is an obvious (to someone other than myself) syntax problem with the code below (SAS 9.4)&amp;nbsp; that will not allow SAS to recognize the filename "predict_2_I&amp;amp;&amp;amp;J (error is file does not exist). Both files are created within the macro. Could someone please point out the syntax or other failure in my code below?&amp;nbsp; Thank you, Rick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table &amp;amp;ts_fcst_&amp;amp;I&amp;amp;J_ as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ts_2_&amp;amp;I&amp;amp;J as a inner join predict_2&amp;amp;I&amp;amp;J as b on&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.group=b.group and a.cvrank=b.cvrank;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638504#M189870</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-08T21:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638506#M189871</link>
      <description>&lt;P&gt;Try adding the period to indicate the end of a macro variable? Note that I can't tell if your macro variable is ts or ts_fcst or ts_fcst_1_3 with i=3 and j=3......and neither can the compiler.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;table &amp;amp;ts._fcst_&amp;amp;I.&amp;amp;J._&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Have you also ran your code with the debugging options on to see how the compiler is seeing it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321440"&gt;@rfrancis&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone, there is an obvious (to someone other than myself) syntax problem with the code below (SAS 9.4)&amp;nbsp; that will not allow SAS to recognize the filename "predict_2_I&amp;amp;&amp;amp;J (error is file does not exist). Both files are created within the macro. Could someone please point out the syntax or other failure in my code below?&amp;nbsp; Thank you, Rick&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table &amp;amp;ts_fcst_&amp;amp;I&amp;amp;J_ as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select * from&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ts_2_&amp;amp;I&amp;amp;J as a inner join predict_2&amp;amp;I&amp;amp;J as b on&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.group=b.group and a.cvrank=b.cvrank;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638506#M189871</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-08T21:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638508#M189873</link>
      <description>Thanks Reeza, see what I can do.</description>
      <pubDate>Wed, 08 Apr 2020 21:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638508#M189873</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-08T21:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638510#M189874</link>
      <description>Could you post more of the macro which to at least show the macro variable definitions before the proc sql step,   &lt;BR /&gt;When you say filename, do you mean table name?  &lt;BR /&gt;It is a good habit to use a period after macro variable names when you use them.&lt;BR /&gt;Use OPTIONS MPRINT to see exactly the code that is generated.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638510#M189874</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-04-08T21:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638511#M189875</link>
      <description>&lt;P&gt;What are the values of &amp;amp;i and &amp;amp;j?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your question text uses: "predict_2_I&amp;amp;&amp;amp;J." which is indeed a &lt;STRONG&gt;very different &lt;/STRONG&gt;thing than "predict_2_&amp;amp;I&amp;amp;J&lt;/P&gt;
&lt;P&gt;If you actually have &amp;amp;&amp;amp;J when the macro processor sees two &amp;amp; it "holds" the first one then resolves &amp;amp;J. The "uses" the held &amp;amp; to resolve.&lt;/P&gt;
&lt;P&gt;So if &amp;amp;j is CAT then &amp;amp;&amp;amp;J =&amp;gt;&amp;amp;Cat. Which would thrown an error if you do not have a macro variable &amp;amp;Cat defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HInt: when you get an error copy the proc or data step code will all the notes and errors from the log and paste into a code box opened on the forum with the &amp;lt;/&amp;gt; icon. &lt;BR /&gt;The code box is important to keep the message windows from reformatting text and moving the diagnostic characters that frequently appear with error messages.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638511#M189875</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T21:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638533#M189892</link>
      <description>Hello, I'm sensitive to the need for a code box. However, I see no such icon anywhere on the page. Sorry.</description>
      <pubDate>Wed, 08 Apr 2020 22:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638533#M189892</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-08T22:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638540#M189897</link>
      <description>Hi Dave, included the full macro below. There are no macro variable definitions, always worked without them, not sure why they are needed now (not saying they are not needed, just lack the necessary knowledge for their inclusion). The primary error is "File Predict_2 does not exist." if this forum uses tags to identify code, I am happy to oblige, just have no knowledge for the tags. I apologize. Thank you for your interest! Rick&lt;BR /&gt;&lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;&lt;BR /&gt;%MACRO combination;&lt;BR /&gt;&lt;BR /&gt;*option spool;&lt;BR /&gt;&lt;BR /&gt;data untrimmed1_&amp;amp;I&amp;amp;J;&lt;BR /&gt;set untrimmed1;&lt;BR /&gt;if group=&amp;amp;I and lagcvrank eq &amp;amp;J; run;&lt;BR /&gt;&lt;BR /&gt;proc surveyselect data=untrimmed1_&amp;amp;I&amp;amp;J method=srs n=2 seed=3965&lt;BR /&gt;out=comb_2 rep=1 noprint; quit;&lt;BR /&gt;&lt;BR /&gt;filename templog dummy;&lt;BR /&gt;*proc printto log=templog; run;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc reg data=comb_2 noprint adjrsq outest=ts_2_est_&amp;amp;I&amp;amp;J&lt;BR /&gt;(keep= group replicate lagcfo lagcfo_cv lagcvrank);&lt;BR /&gt;by group lagcvrank replicate;&lt;BR /&gt;model cfo = lagcfo lagcfo_cv / noint noprint adjrsq;&lt;BR /&gt;output out=predict_2_&amp;amp;I&amp;amp;J; quit;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data ts_2_est_&amp;amp;I&amp;amp;J;&lt;BR /&gt;set ts_2_est_&amp;amp;I&amp;amp;J;&lt;BR /&gt;tse_2a=lagcfo;&lt;BR /&gt;tse_2b=lagcfo_cv;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data int&amp;amp;I&amp;amp;J;&lt;BR /&gt;set predict_2;&lt;BR /&gt;int_raw=cfo-predict2;&lt;BR /&gt;&lt;BR /&gt;proc means data=ts_2_est_&amp;amp;I&amp;amp;J noprint; format ts_2a ts_2b 12.6;&lt;BR /&gt;by group lagcvrank;&lt;BR /&gt;var tse_2a tse_2b;&lt;BR /&gt;output out=ts_2_&amp;amp;I&amp;amp;J (drop=_TYPE_ _FREQ_) median(tse_2a)=ts_2a&lt;BR /&gt;median(tse_2b)=ts_2b;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc means data=int&amp;amp;I&amp;amp;J noprint;&lt;BR /&gt;by group lagcvrank;&lt;BR /&gt;var int_raw;&lt;BR /&gt;output out=med_int_&amp;amp;I&amp;amp;J (drop=_TYPE_ _FREQ_) median(int_raw)=int;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table ts_fcst_&amp;amp;I&amp;amp;J_ as&lt;BR /&gt;select * from&lt;BR /&gt;ts_2_&amp;amp;I.&amp;amp;J. as a inner join predict_2_&amp;amp;I&amp;amp;J as b on&lt;BR /&gt;a.group=b.group and a.cvrank=b.cvrank;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table ts_fcst_&amp;amp;I&amp;amp;J as&lt;BR /&gt;select * from&lt;BR /&gt;ts_fcst_&amp;amp;I&amp;amp;J_ as a inner join med_int_&amp;amp;I&amp;amp;J on&lt;BR /&gt;a.group=b.group and a.cvrank=b.cvrank;&lt;BR /&gt;&lt;BR /&gt;*proc printto; run;&lt;BR /&gt;&lt;BR /&gt;%MEND combination;&lt;BR /&gt;%MACRO LOOP;&lt;BR /&gt;%DO I=1994 %TO 2018;&lt;BR /&gt;%DO J=0 %TO 4;&lt;BR /&gt;%combination;&lt;BR /&gt;%END;&lt;BR /&gt;%END;&lt;BR /&gt;%MEND LOOP; %LOOP;</description>
      <pubDate>Wed, 08 Apr 2020 23:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638540#M189897</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-08T23:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638543#M189898</link>
      <description>Hi Dave, corrected a few mistakes, added a few tweaks, seems to run now. FWIW, Included the working version below.. Sorry to waste your time. Rick&lt;BR /&gt;&lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;&lt;BR /&gt;%MACRO combination;&lt;BR /&gt;&lt;BR /&gt;*option spool;&lt;BR /&gt;&lt;BR /&gt;data untrimmed1_&amp;amp;I&amp;amp;J;&lt;BR /&gt;set untrimmed1;&lt;BR /&gt;if group=&amp;amp;I and lagcvrank eq &amp;amp;J; run;&lt;BR /&gt;&lt;BR /&gt;proc surveyselect data=untrimmed1_&amp;amp;I&amp;amp;J method=srs n=2 seed=3965&lt;BR /&gt;out=comb_2 rep=1 noprint; quit;&lt;BR /&gt;&lt;BR /&gt;filename templog dummy;&lt;BR /&gt;*proc printto log=templog; run;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc reg data=comb_2 noprint adjrsq outest=ts_2_est_&amp;amp;I&amp;amp;J&lt;BR /&gt;(keep= group replicate lagcfo lagcfo_cv lagcvrank);&lt;BR /&gt;by group lagcvrank replicate;&lt;BR /&gt;model cfo = lagcfo lagcfo_cv / noint noprint adjrsq;&lt;BR /&gt;output out=predict_2_&amp;amp;I&amp;amp;J; quit;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data ts_2_est_&amp;amp;I&amp;amp;J;&lt;BR /&gt;set ts_2_est_&amp;amp;I&amp;amp;J;&lt;BR /&gt;tse_2a=lagcfo;&lt;BR /&gt;tse_2b=lagcfo_cv;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data int&amp;amp;I&amp;amp;J;&lt;BR /&gt;set predict_2_&amp;amp;i&amp;amp;J;&lt;BR /&gt;*int_raw=cfo-predict2;&lt;BR /&gt;&lt;BR /&gt;proc means data=ts_2_est_&amp;amp;I&amp;amp;J noprint; format ts_2a ts_2b 12.6;&lt;BR /&gt;by group lagcvrank;&lt;BR /&gt;var tse_2a tse_2b;&lt;BR /&gt;output out=ts_2_&amp;amp;I&amp;amp;J (drop=_TYPE_ _FREQ_) median(tse_2a)=ts_2a&lt;BR /&gt;median(tse_2b)=ts_2b;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;*proc means data=int&amp;amp;I&amp;amp;J noprint;&lt;BR /&gt;*by group lagcvrank;&lt;BR /&gt;*var int_raw;&lt;BR /&gt;*output out=med_int_&amp;amp;I&amp;amp;J (drop=_TYPE_ _FREQ_) median(int_raw)=int;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table ts_fcst_&amp;amp;I&amp;amp;J._ as&lt;BR /&gt;select * from&lt;BR /&gt;ts_2_&amp;amp;I&amp;amp;J as a inner join predict_2_&amp;amp;I&amp;amp;J as b on&lt;BR /&gt;a.group=b.group and a.lagcvrank=b.lagcvrank;&lt;BR /&gt;&lt;BR /&gt;*proc sql;&lt;BR /&gt;*create table &amp;amp;ts_fcst_&amp;amp;I&amp;amp;J as&lt;BR /&gt;*select * from&lt;BR /&gt;*ts_fcst_&amp;amp;I&amp;amp;J_ as a inner join med_int_&amp;amp;I&amp;amp;J on&lt;BR /&gt;*a.group.=b.group. and a.cvrank.=b.cvrank.;&lt;BR /&gt;&lt;BR /&gt;*proc printto; run;&lt;BR /&gt;&lt;BR /&gt;%MEND combination;&lt;BR /&gt;%MACRO LOOP;&lt;BR /&gt;%DO I=1994 %TO 2018;&lt;BR /&gt;%DO J=0 %TO 4;&lt;BR /&gt;%combination;&lt;BR /&gt;%END;&lt;BR /&gt;%END;&lt;BR /&gt;%MEND LOOP; %LOOP;</description>
      <pubDate>Wed, 08 Apr 2020 23:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638543#M189898</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-08T23:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638555#M189902</link>
      <description>&lt;P&gt;Here they are:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 788px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38070i44CB950BB7446AC0/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 01:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638555#M189902</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-09T01:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL inside MACRO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638743#M189956</link>
      <description>&lt;P&gt;Thank you!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 17:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-inside-MACRO/m-p/638743#M189956</guid>
      <dc:creator>rfrancis</dc:creator>
      <dc:date>2020-04-09T17:01:46Z</dc:date>
    </item>
  </channel>
</rss>

