<?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: Is it possible to call an %include statement inside a SAS Data statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616447#M180468</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271996"&gt;@hiteshchauhan1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;oh that's a typo actually i am running an entirely different code and i can say it has no typo, the thing is i can't share the actual code here so i have made an example code that i put in the question i asked.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but the point remains, you do not have valid working legal SAS code. You need to have that or %INCLUDE won't work. If you can't show the actual code to us, then its really hard to help you.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jan 2020 13:13:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-01-10T13:13:45Z</dc:date>
    <item>
      <title>Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616397#M180445</link>
      <description>&lt;P&gt;Okay so i want to call a separate SAS Program using a SAS Macro inside a SAS Data statement, is it possible to do this in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is an example of ewhat i want to achieve:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro tempMD;&lt;BR /&gt;%if %sysfunc(compress(%sysfunc(upcase(&amp;amp;dynamicMD)))) = ON %then %do;&lt;BR /&gt;%include "&amp;amp;codepath/MDfactor_VADB.sas";&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put Check = &amp;amp;dynamicMD;&lt;BR /&gt;%end;&lt;BR /&gt;%mend tempMD;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test2;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 = "Active"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%tempMD;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 = "Inactive"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%tempMD;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it doable in sas?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 09:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616397#M180445</guid>
      <dc:creator>hiteshchauhan1</dc:creator>
      <dc:date>2020-01-10T09:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616398#M180446</link>
      <description>&lt;P&gt;Yes, as long as the SAS code generated by the macro produces syntactically correct DATA step statements. Why don't you just try it?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 09:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616398#M180446</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-01-10T09:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616418#M180452</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;I tried it and the macro that calls another program worked just fine but the statements i am writing after it in the data statement are giving me the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know why am i getting this error and is there a way around it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616418#M180452</guid>
      <dc:creator>hiteshchauhan1</dc:creator>
      <dc:date>2020-01-10T11:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616434#M180460</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271996"&gt;@hiteshchauhan1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;I tried it and the macro that calls another program worked just fine but the statements i am writing after it in the data statement are giving me the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know why am i getting this error and is there a way around it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your macro does not create valid SAS code at the place where it is called. Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to see the code of the %include, and the code created by the macro. This needs to fit in with the data step where you call it.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616434#M180460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-10T12:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616435#M180461</link>
      <description>&lt;P&gt;As stated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;, the %INCLUDE needs to create valid legal working DATA step code, and apparently it does not do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to create valid legal working DATA step code without %INCLUDE, and once you have that working, you can move part of the code to a .sas file which you can %INCLUDE. If you can't get the code to work properly without %INCLUDE, then it will never work properly with %INCLUDE.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616435#M180461</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-10T12:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616443#M180465</link>
      <description>&lt;P&gt;In your example code there is a missing semicolon:&lt;/P&gt;
&lt;PRE&gt;Var1 = "Inactive"   &amp;lt;---- This needs a semicolon to end the assignment statement.&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616443#M180465</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-01-10T12:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616444#M180466</link>
      <description>&lt;P&gt;This is a very good catch,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;. And it goes back to the point I was making, that first&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271996"&gt;@hiteshchauhan1&lt;/a&gt;&amp;nbsp; has to get the code to work without %INCLUDE, then you can move part of the code to a separate .sas file and %INCLUDE it if you want.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616444#M180466</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-10T13:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616446#M180467</link>
      <description>&lt;P&gt;oh that's a typo actually i am running an entirely different code and i can say it has no typo, the thing is i can't share the actual code here so i have made an example code that i put in the question i asked.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616446#M180467</guid>
      <dc:creator>hiteshchauhan1</dc:creator>
      <dc:date>2020-01-10T13:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616447#M180468</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271996"&gt;@hiteshchauhan1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;oh that's a typo actually i am running an entirely different code and i can say it has no typo, the thing is i can't share the actual code here so i have made an example code that i put in the question i asked.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but the point remains, you do not have valid working legal SAS code. You need to have that or %INCLUDE won't work. If you can't show the actual code to us, then its really hard to help you.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616447#M180468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-10T13:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616451#M180470</link>
      <description>&lt;P&gt;Makes sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest you make a small example which replicates the problem.&amp;nbsp; And then post all of that&amp;nbsp; example code (both the main code file and the file that is included).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can post a small full example of the code that replicates the problem, people will be able to help you figure out what is going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Often when you try to build a small example of a problem, that code ends up working, and then on your own you can look back at your original code and you realize what is wrong in the original code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay, I made a little example that works.&amp;nbsp; The main code is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro tempMD;
  %global dynamicMD ;
  %if %sysfunc(compress(%sysfunc(upcase(&amp;amp;dynamicMD)))) = ON %then %do;
    %include "c:\junk\foo.sas";
  %end;
  %else %do;
    %put Check = &amp;amp;dynamicMD;
  %end;
%mend tempMD;

options mprint source2 ;
%let dynamicMD=ON ;

data test2;
  set sashelp.class(obs=3);
  length Var1 $8 ;
  Var1 = "Active" ;
  %tempMD; 
  Var1 = "Inactive" ;
  %tempMD;
run;&lt;/PRE&gt;
&lt;P&gt;The code in the include file c:\junk\foo.sas is:&lt;/P&gt;
&lt;PRE&gt;put "include ran! " (_all_)(=) ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would he helpful if you could make an example like that, closer to your real code, which shows an error.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616451#M180470</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-01-10T13:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616461#M180479</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Including a file this way is equivalent to copying/pasting the code from the included file.&lt;/P&gt;
&lt;P&gt;Since the inclusion is made inside a data step, the included code shouldn't contain&amp;nbsp; any&lt;/P&gt;
&lt;P&gt;data steps or procs but only instructions that are valid inside a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, the following code won't work :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename a "c:/temp/incl.sas";

data _NULL_;
file a;
put "data b; set sahelp.class; run;";
run;

data a;
x=1;

%include "c:/temp/incl.sas";

put x=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the generated code will be :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
x=1;

data b; 
set sashelp.class; 
run;

put x=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;=&amp;gt; the "run" after "set sashelp.class" will exit the data step so we end up with a put instruction outside the data step.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616461#M180479</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-01-10T13:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to call an %include statement inside a SAS Data statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616588#M180517</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Okay so i want to call a separate SAS Program using a SAS Macro inside a SAS Data statement, is it possible to do this in SAS.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Your example will generate one of two possible data step, depending the value of the macro variable&amp;nbsp;dynamicMD.&amp;nbsp; So either it is "ON" in which case you are going to run:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  set test;
  Var1 = "Active"
  %include "&amp;amp;codepath/MDfactor_VADB.sas";
  Var1 = "Inactive"
  %include "&amp;amp;codepath/MDfactor_VADB.sas";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Otherwise you are running&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put Check = &amp;amp;dynamicMD;&lt;BR /&gt;%put Check = &amp;amp;dynamicMD;
data test2;
  set test;
  Var1 = "Active"
  Var1 = "Inactive"
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Whether this works depends on what you are trying to do.&amp;nbsp; So if the INCLUDE file only includes data step statements that could validly be placed between those two assignment statements.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that calling a macro "inside" of a data step is a bit backwards. The output of a SAS macro is lines of code for SAS to compile and run.&amp;nbsp; The macro processor is just tool for saving you from having to type the same lines of code over and over.&amp;nbsp; So in general the macro processor has finished its work generating the code BEFORE the SAS processor has compiled that data step and run it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; Using %INCLUDE is just like copying and pasting the lines of code from the file into that place in the file.&amp;nbsp; So using %INCLUDE inside of a data step is normally not done.&amp;nbsp; It will only work if the file only includes data step statements, like assignment statement, if statements, infile, etc .&amp;nbsp; If the file includes multiple data and/or proc steps then you would include the file in between two steps in your main program.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really need to run some whole subprocess based on decisions based on data available in a data step you would normally do that by generating the code and then calling it.&amp;nbsp; You can use CALL EXECUTE() to do that.&amp;nbsp; Or just write the lines of code to a new file and %include it after the data step finishes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really feel there is some value in trying to run one or more full SAS steps while a data step is actively running you will have to resort to use the DOSUBL() function.&amp;nbsp; And that could potentially cause a lot of confusion, and generally is not worth the effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 20:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-call-an-include-statement-inside-a-SAS-Data/m-p/616588#M180517</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-10T20:13:35Z</dc:date>
    </item>
  </channel>
</rss>

