<?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: %INCLUDE statement not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764669#M242224</link>
    <description>&lt;P&gt;Please show us the LOG of both cases, with %include and without %include. We need to see the entire log, all of it, every single line, with nothing chopped out. Please copy the log as text and &lt;FONT color="#FF0000"&gt;paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon&lt;/FONT&gt;. &lt;STRONG&gt;DO NOT SKIP THE PART IN RED&lt;/STRONG&gt;.&lt;/P&gt;</description>
    <pubDate>Sun, 29 Aug 2021 12:55:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-08-29T12:55:03Z</dc:date>
    <item>
      <title>%INCLUDE statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764668#M242223</link>
      <description>&lt;P&gt;I have a macro program, inside this macro program there is piece of code which is common across multiple programs. I am trying to call this piece of code by %include statement. But as I use %include it starts giving&amp;nbsp;&lt;STRONG&gt;ERROR: The %DO statement is not valid in open code.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without %INCLUDE it works fine. My understanding is %include gets code from external file into current program so ideally it should work, not sure where getting wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample Program -&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test1;&lt;BR /&gt;set test;&lt;BR /&gt;CALL SYMPUT('N',_N_);&lt;BR /&gt;CALL SYMPUTX(CAT('CTY',_N_),ctry_code);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*Below DO loop I am putting in external file*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*%include "&amp;lt;location&amp;gt;/test_inc.sas";*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%DO I=1 %TO &amp;amp;N.;&lt;/P&gt;&lt;P&gt;DATA _TMP;&lt;BR /&gt;SET dim.&amp;amp;ds.;&lt;BR /&gt;where &amp;amp;fld_nm. eq "&amp;amp;&amp;amp;cty&amp;amp;i.";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;OPTIONS VALIDVARNAME=UPCASE;&lt;/P&gt;&lt;P&gt;proc export data=_TMP outfile="&amp;lt;location&amp;gt;"&lt;BR /&gt;dbms=csv replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 12:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764668#M242223</guid>
      <dc:creator>PRAVIN_JAIN</dc:creator>
      <dc:date>2021-08-29T12:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: %INCLUDE statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764669#M242224</link>
      <description>&lt;P&gt;Please show us the LOG of both cases, with %include and without %include. We need to see the entire log, all of it, every single line, with nothing chopped out. Please copy the log as text and &lt;FONT color="#FF0000"&gt;paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon&lt;/FONT&gt;. &lt;STRONG&gt;DO NOT SKIP THE PART IN RED&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 12:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764669#M242224</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-29T12:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: %INCLUDE statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764696#M242230</link>
      <description>&lt;PRE&gt;Failed Log - 
1                                                          The SAS System                              19:52 Sunday, August 29, 2021

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program (4)';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTNAME='';
7          %LET _SASPROGRAMFILE=;
8          
9          ODS _ALL_ CLOSE;
10         OPTIONS DEV=ACTIVEX;
11         GOPTIONS XPIXELS=0 YPIXELS=0;
12         FILENAME EGSR TEMP;
13         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
14             STYLE=HtmlBlue
15             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
16             NOGTITLE
17             NOGFOOTNOTE
18             GPATH=&amp;amp;sasworklocation
SYMBOLGEN:  Macro variable SASWORKLOCATION resolves to 
            "/localwork2/SAS_work29EB0000FD28_hkpa2ls0136/SAS_work57120000FD28_hkpa2ls0136/"
19             ENCODING=UTF8
20             options(rolap="on")
21         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
22         
23         GOPTIONS ACCESSIBLE;
24         options symbolgen mlogic mprint;
25         
26         %MACRO TEST(ds,fld_nm);
27         
28         libname dim "&amp;lt;location&amp;gt;" access =r;
29         
30         proc sql;
31         create table test as
32         select distinct &amp;amp;fld_nm. from dim.&amp;amp;ds.;
33         quit;
34         
35         data test1;
36         set test(WHERE=(&amp;amp;fld_nm. EQ 'IND'));
37         CALL SYMPUT('N',_N_);
38         CALL SYMPUTX(CAT('CTY',_N_),&amp;amp;fld_nm.);
39         run;
40         
41         %PUT &amp;amp;N.;
42         
43         %include "location";
44         
45         %MEND;
46         
47         %test(dim_product,ctry_cde);
MLOGIC(TEST):  Beginning execution.
MLOGIC(TEST):  Parameter DS has value dim_product
MLOGIC(TEST):  Parameter FLD_NM has value ctry_cde
MPRINT(TEST):   libname dim "&amp;lt;location&amp;gt;" access =r;
NOTE: Libref DIM was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: &amp;lt;location&amp;gt;
MPRINT(TEST):   proc sql;
2                                                          The SAS System                              19:52 Sunday, August 29, 2021

SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
SYMBOLGEN:  Macro variable DS resolves to dim_product
MPRINT(TEST):   create table test as select distinct ctry_cde from dim.dim_product;
NOTE: Compression was disabled for data set WORK.TEST because compression overhead would increase the size of the data set.
NOTE: Table WORK.TEST created, with 8 rows and 1 columns.

MPRINT(TEST):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds
      

MPRINT(TEST):   data test1;
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
MPRINT(TEST):   set test(WHERE=(ctry_cde EQ 'IND'));
MPRINT(TEST):   CALL SYMPUT('N',_N_);
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
MPRINT(TEST):   CALL SYMPUTX(CAT('CTY',_N_),ctry_cde);
MPRINT(TEST):   run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      3998:233   
NOTE: Compression was disabled for data set WORK.TEST1 because compression overhead would increase the size of the data set.
NOTE: There were 1 observations read from the data set WORK.TEST.
      WHERE ctry_cde='IND';
NOTE: The data set WORK.TEST1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

MLOGIC(TEST):  %PUT &amp;amp;N.
SYMBOLGEN:  Macro variable N resolves to            1
1
ERROR: The %DO statement is not valid in open code.
MPRINT(TEST):   DATA _TMP;
SYMBOLGEN:  Macro variable DS resolves to dim_product
MPRINT(TEST):   SET dim.dim_product;
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
WARNING: Apparent symbolic reference I not resolved.
SYMBOLGEN:  Unable to resolve the macro variable reference &amp;amp;i
WARNING: Apparent symbolic reference CTY not resolved.
WARNING: Apparent symbolic reference I not resolved.
MPRINT(TEST):   where ctry_cde eq "&amp;amp;cty&amp;amp;i.";
MPRINT(TEST):   run;

NOTE: There were 0 observations read from the data set DIM.DIM_PRODUCT.
      WHERE ctry_cde='&amp;amp;cty&amp;amp;i.';
NOTE: The data set WORK._TMP has 0 observations and 31 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.02 seconds
      

MPRINT(TEST):   proc print data=_tmp;
MPRINT(TEST):   run;

3                                                          The SAS System                              19:52 Sunday, August 29, 2021

NOTE: No observations in data set WORK._TMP.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

ERROR: The %END statement is not valid in open code.
MLOGIC(TEST):  Ending execution.
60         
61         GOPTIONS NOACCESSIBLE;
62         %LET _CLIENTTASKLABEL=;
63         %LET _CLIENTPROCESSFLOWNAME=;
64         %LET _CLIENTPROJECTPATH=;
65         %LET _CLIENTPROJECTNAME=;
66         %LET _SASPROGRAMFILE=;
67         
68         ;*';*";*/;quit;run;
69         ODS _ALL_ CLOSE;
70         
71         
72         QUIT; RUN;
73         

&lt;/PRE&gt;&lt;PRE&gt;Success Log (without INCLUDE) - 

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
22         
23         GOPTIONS ACCESSIBLE;
24         options symbolgen mlogic mprint;
25         
26         %MACRO TEST(ds,fld_nm);
27         
28         libname dim "&amp;lt;location&amp;gt;" access =r;
29         
30         proc sql;
31         create table test as
32         select distinct &amp;amp;fld_nm. from dim.&amp;amp;ds.;
33         quit;
34         
35         data test1;
36         set test(WHERE=(&amp;amp;fld_nm. EQ 'IND'));
37         CALL SYMPUT('N',_N_);
38         CALL SYMPUTX(CAT('CTY',_N_),&amp;amp;fld_nm.);
39         run;
40         
41         %PUT &amp;amp;N.;
42         /*%PUT &amp;amp;CTY1. &amp;amp;CTY5.;*/
43         
44         /*%include "&amp;lt;location&amp;gt;";*/
45         
46         %DO I=1 %TO &amp;amp;N.;
47         
48         DATA _TMP;
49         SET dim.&amp;amp;ds.;
50         where &amp;amp;fld_nm. eq "&amp;amp;&amp;amp;cty&amp;amp;i.";
51         run;
52         
53         PROC PRINT DATA=_TMP;
54         RUN;
55         
2                                                          The SAS System                              19:52 Sunday, August 29, 2021

56         %END;
57         
58         
59         %MEND;
60         
61         %test(dim_product,ctry_cde);
MLOGIC(TEST):  Beginning execution.
MLOGIC(TEST):  Parameter DS has value dim_product
MLOGIC(TEST):  Parameter FLD_NM has value ctry_cde
MPRINT(TEST):   libname dim “&amp;lt;Location&amp;gt;" access =r;
NOTE: Libref DIM was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: &amp;lt;Location&amp;gt;
MPRINT(TEST):   proc sql;
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
SYMBOLGEN:  Macro variable DS resolves to dim_product
MPRINT(TEST):   create table test as select distinct ctry_cde from dim.dim_product;
NOTE: Compression was disabled for data set WORK.TEST because compression overhead would increase the size of the data set.
NOTE: Table WORK.TEST created, with 8 rows and 1 columns.

MPRINT(TEST):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds
      

MPRINT(TEST):   data test1;
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
MPRINT(TEST):   set test(WHERE=(ctry_cde EQ 'IND'));
MPRINT(TEST):   CALL SYMPUT('N',_N_);
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
MPRINT(TEST):   CALL SYMPUTX(CAT('CTY',_N_),ctry_cde);
MPRINT(TEST):   run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      3651:233   
NOTE: Compression was disabled for data set WORK.TEST1 because compression overhead would increase the size of the data set.
NOTE: There were 1 observations read from the data set WORK.TEST.
      WHERE ctry_cde='IND';
NOTE: The data set WORK.TEST1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.13 seconds
      cpu time            0.02 seconds
      

MLOGIC(TEST):  %PUT &amp;amp;N.
SYMBOLGEN:  Macro variable N resolves to            1
1
SYMBOLGEN:  Macro variable N resolves to            1
MLOGIC(TEST):  %DO loop beginning; index variable I; start value is 1; stop value is 1; by value is 1.  
MPRINT(TEST):   DATA _TMP;
SYMBOLGEN:  Macro variable DS resolves to dim_product
MPRINT(TEST):   SET dim.dim_product;
SYMBOLGEN:  Macro variable FLD_NM resolves to ctry_cde
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  Macro variable CTY1 resolves to IND
MPRINT(TEST):   where ctry_cde eq "IND";
3                                                          The SAS System                              19:52 Sunday, August 29, 2021

MPRINT(TEST):   run;

NOTE: There were 55 observations read from the data set DIM.DIM_PRODUCT.
      WHERE ctry_cde='IND';
NOTE: The data set WORK._TMP has 55 observations and 31 variables.
NOTE: Compressing data set WORK._TMP increased size by 100.00 percent. 
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      

MPRINT(TEST):   PROC PRINT DATA=_TMP;
MPRINT(TEST):   RUN;

NOTE: There were 55 observations read from the data set WORK._TMP.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.15 seconds
      cpu time            0.16 seconds
      

MLOGIC(TEST):  %DO loop index variable I is now 2; loop will not iterate again.
MLOGIC(TEST):  Ending execution.&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Aug 2021 15:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764696#M242230</guid>
      <dc:creator>PRAVIN_JAIN</dc:creator>
      <dc:date>2021-08-29T15:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: %INCLUDE statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764705#M242232</link>
      <description>&lt;P&gt;Thank you. Please run&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then run the failed code again, modifying the %include code to say &lt;FONT face="courier new,courier"&gt;%include "location"/source2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us the complete log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 15:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764705#M242232</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-29T15:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: %INCLUDE statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764713#M242234</link>
      <description>&lt;P&gt;You can't do that.&amp;nbsp; Here is a simplified test case.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code ;
  put '%do i=1 %to &amp;amp;n; put &amp;amp;=i; %end;';
run;

%macro test(n);
 %put &amp;amp;=sysmacroname &amp;amp;=n;
 %include code / source2;
%mend;

%test(1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The issue is that when %TEST() is compiled it does NOT include the code from the file into the macro definition.&amp;nbsp; It just puts the %INCLUDE statement into the macro definition.&amp;nbsp; Therefore when the %INCLUDE runs the macro compiler is not running anymore.&amp;nbsp; So the code in the include file has to be code that can run as open code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For my simplified solution the fix is to change the %INCLUDE file to &lt;STRONG&gt;define&lt;/STRONG&gt; and &lt;STRONG&gt;call&lt;/STRONG&gt; its own macro to wrap around the %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro _code_;
%local i;
%do i=1 %to &amp;amp;n;
  %put &amp;amp;=sysmacroname &amp;amp;=i;
%end;
%mend;
%_code_;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;15    %test(1);
SYSMACRONAME=TEST N=1
NOTE: %INCLUDE (level 1) file CODE is file ....
16   +%macro _code_;
17   +%local i;
18   +%do i=1 %to &amp;amp;n;
19   +  %put &amp;amp;=sysmacroname &amp;amp;=i;
20   +%end;
21   +%mend;
22   +%_code_;
SYSMACRONAME=_CODE_ I=1
MPRINT(TEST):  ;
NOTE: %INCLUDE (level 1) ending.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 19:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/INCLUDE-statement-not-working/m-p/764713#M242234</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-29T19:49:49Z</dc:date>
    </item>
  </channel>
</rss>

