<?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: Rerunning new %LET statements - easier way? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677075#M204200</link>
    <description>Is there a way to use the %INCLUDE statement and call the lines of code within the same SAS session? Just curious.</description>
    <pubDate>Sun, 16 Aug 2020 15:00:34 GMT</pubDate>
    <dc:creator>MelissaM</dc:creator>
    <dc:date>2020-08-16T15:00:34Z</dc:date>
    <item>
      <title>Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677067#M204197</link>
      <description>&lt;P&gt;Here's what I'm currently doing, which is tedious:&lt;/P&gt;&lt;P&gt;I run the 1st %LET statement, scroll down, run the program.&lt;/P&gt;&lt;P&gt;I run the 2nd %LET statement, scroll down, run the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a (much) simpler version of what I'm doing with sashelp.cars (attached)&lt;/P&gt;&lt;P&gt;&lt;U&gt;Here's the&amp;nbsp;primary thing:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I &lt;STRONG&gt;DO NOT &lt;/STRONG&gt;want a macro around the PROC PRINT statement. I know how to do that.&lt;/P&gt;&lt;P&gt;I just want to know if there's a way to end each section of %LET statements with 'something' that calls the PROC PRINT program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;9.4M6 Windows&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 14:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677067#M204197</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2020-08-16T14:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677073#M204199</link>
      <description>&lt;P&gt;Why did you attach a file to post 20 lines of code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET FILE=FILE1;
%LET VAR=MODEL;
%LET COND=Type='Sedan';
*Can I add a line of code here to run lines 18-22;

%LET FILE=FILE2;
%LET VAR=MODEL;
%LET COND=Type='SUV';
*Can I add a line of code here to run lines 18-22;

%LET FILE=FILE3;
%LET VAR=MODEL;
%LET COND=Type='Wagon';
*Can I add a line of code here to run lines 18-22;

%LET FILE=FILE4;
%LET VAR=MODEL;
%LET COND=Type='Truck';*Can I add a line of code here to run lines 18-22;

ODS RTF file="C:/temp/&amp;amp;&amp;amp;FILE..rtf";
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;
  VAR &amp;amp;VAR;
  WHERE &amp;amp;COND;
RUN;
ODS RTF CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if you want to re-run a constant block of text you can either type it again or use your editor to insert it. Most editors including the editors in the various SAS user interfaces have that feature.&amp;nbsp; You could have the block of code in another editor window and run it from there.&amp;nbsp; You could have the block of code in a file on the SAS server and use a %INCLUDE statement to run it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "mycode.sas";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could put the code into a macro variable and then just expand the macro variable to run it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('code','ODS RTF file="C:/temp/&amp;amp;FILE..rtf";
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;
  VAR &amp;amp;VAR;
  WHERE &amp;amp;COND;
RUN;
ODS RTF CLOSE;');
run;
...
&amp;amp;code.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could define a macro that takes no parameters and just uses the existing macro variables.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro code;
ODS RTF file="C:/temp/&amp;amp;FILE..rtf";
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;
  VAR &amp;amp;VAR;
  WHERE &amp;amp;COND;
RUN;
ODS RTF CLOSE;
%mend;
...
%code&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could define a macro that does have parameters, but uses the existing macro variables when no values are passed in the parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro code(outfile,varlist,wherecond);
%if 0=%length(&amp;amp;outfile) %then %let outfile=&amp;amp;file;
%if 0=%length(&amp;amp;varlist) %then %let varlist=&amp;amp;var;
%if 0=%length(&amp;amp;wherecond) %then %let wherecond=&amp;amp;cond;
ODS RTF file="C:/temp/&amp;amp;OUTFILE..rtf";
options nodate pageno=1 linesize=80 pagesize=30 obs=10;
PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;
  VAR &amp;amp;VARLIST;
  WHERE &amp;amp;WHERCOND;
RUN;
ODS RTF CLOSE;
%mend;
...
%code()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you could put the values into a dataset instead of typing so many %LET statements and use CALL EXECUTE() to generate the code to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set list;
  call execute(catx(' '
,'ODS RTF file=' ,quote(cats('C:/temp/',file,'.rtf')
,';options nodate pageno=1 linesize=80 pagesize=30 obs=10;'
,'PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;'
,'VAR',var,';'
,'WHERE',cond,';'
,'RUN;'
,'ODS RTF CLOSE;'
));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Aug 2020 15:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677073#M204199</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T15:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677075#M204200</link>
      <description>Is there a way to use the %INCLUDE statement and call the lines of code within the same SAS session? Just curious.</description>
      <pubDate>Sun, 16 Aug 2020 15:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677075#M204200</guid>
      <dc:creator>MelissaM</dc:creator>
      <dc:date>2020-08-16T15:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677076#M204201</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72050"&gt;@MelissaM&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Is there a way to use the %INCLUDE statement and call the lines of code within the same SAS session? Just curious.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are using Display Manager or SAS/Studio you can just highlight the lines of code with your mouse of cursor keys and submit them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to run SAS interactively without Display Manager. So that you have to type each line at the terminal. Then there is a feature to recall and re-run specific lines from earlier in your session. But then you don't have any of the nice features of interactive SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 15:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677076#M204201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T15:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677078#M204202</link>
      <description>&lt;P&gt;As you "&lt;STRONG&gt;DO NOT&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;want a macro around the PROC PRINT statement."&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;may be you'll prefer next method: ( tested code without ODS )&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   input file $ var $ type $;
   call execute("options nodate pageno=1linesize=80 pagesize=30 obs=10;");
   call execute('ODS RTF file="C:/temp/' || strip(file) || '.rtf";');
   call execute("PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;");
   call execute("var " || strip(var) || ";");
   call execute("where type='" || strip(type) || "';  RUN; ODS RTF CLOSE");
cards;
file1  model  Sedan
file2  model  SUV
file3  model  Wagon
file4  model  Truck;
run cancel; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 15:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677078#M204202</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-16T15:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677081#M204203</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I &lt;STRONG&gt;DO NOT &lt;/STRONG&gt;want a macro around the PROC PRINT statement. I know how to do that.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A macro, of course, is one tool in SAS that allows you to use specific blocks of code repeatedly, and via the use of macro parameters, change certain pieces of text in that block of code. You make your own life more difficult by excluding a method that SAS specifically created for the purpose.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So, yes of course, the other methods, such as %include, CALL EXECUTE and CALL SYMPUTX all work, but I don't see what you gain in this situation (and in my opinion, they are harder to code or have other drawbacks).&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 16:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677081#M204203</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-16T16:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677083#M204204</link>
      <description>&lt;P&gt;Not sure why you don't want to use a macro. Regardless, you could consider using the dosubl routine instead of call execute.&lt;BR /&gt;&lt;BR /&gt;Call execute stacks the statements you pass to it so they run after the data step. The dosubl routine calls them immediately. That allows you to not worry about concatenating the data step variables (as suggested in this very nice alternative) and dealing with where quotes go when constructing the code string. Just use macro variable references instead - and single quotes for the code string, thus preventing resolution during compile of the data step.&lt;BR /&gt;&lt;BR /&gt;The array _char is used to load the values of the current row into macro vars.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   input file $ var $ type $;
   array _char(*) _character_;
   do i = 1 to dim(_char);
      call symputx(vname(_char(i)),_char(i));
   end;
   codeline = 'options nodate pageno=1 linesize=80 pagesize=30 obs=10;'
            ||'ODS RTF file="C:/temp/&amp;amp;file..rtf";'
            ||'PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;'
            ||'var &amp;amp;var;'
            ||'where type="&amp;amp;type"; RUN; ODS RTF CLOSE;'
   ; 
   rc = dosubl(codeline); 
cards;
file1  model  Sedan
file2  model  SUV
file3  model  Wagon
file4  model  Truck
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Aug 2020 16:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677083#M204204</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2020-08-16T16:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677087#M204208</link>
      <description>&lt;P&gt;And if the code you want to use is relatively static you can save it in a file (including the macro variable references) and use the dosub routine instead. The difference between them is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;dosubl expects as its argument a single character string which is the lines of code you want to execute.&lt;/LI&gt;
&lt;LI&gt;dosub expects as its argument a character string whose value is the fileref that points to the code to be executed.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is that code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code 'C:\temp\LetStmtAlternative.sas';
data _null_;
   input file $ var $ type $;
   array _char(*) _character_;
   do i = 1 to dim(_char);
      call symputx(vname(_char(i)),_char(i));
   end;
   rc = dosub('code'); 
cards;
file1  model  Sedan
file2  model  SUV
file3  model  Wagon
file4  model  Truck
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here is the contents of the file pointed to by the filename statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nodate pageno=1 linesize=80 pagesize=30 obs=10;
ODS RTF file="C:/temp/&amp;amp;file..rtf";
PROC PRINT DATA=SASHELP.CARS NOOBS LABEL;
var &amp;amp;var;
where type="&amp;amp;type";
RUN;
ODS RTF CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The advantage here is there is absolutely no quoting issue - you are running the code just like it is %included - but you don't have to generate the %include statement to be passed along for execution.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 16:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677087#M204208</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2020-08-16T16:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677088#M204209</link>
      <description>&lt;P&gt;Your code works fine with CALL EXECUTE also. The macro variables set by the CALL SYMPUT will be resolved when the CALL EXECUTE runs.&amp;nbsp; Just make sure to use single quotes in around the text passed to CALL EXECUTE(), just like you did for DOSUBL().&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 16:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677088#M204209</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T16:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677093#M204214</link>
      <description>&lt;P&gt;I have tested the code replacing line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc = dosubl(codeline);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(codeline);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ant it worked fine too.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 17:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677093#M204214</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-16T17:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677096#M204217</link>
      <description>&lt;P&gt;Interesting.&lt;/P&gt;
&lt;P&gt;I wonder when that changed. I know that, as this blog post says,&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/&lt;/A&gt;, that call execute had a timing issue and always used the values set for the macro variables on the last execution of the data step.&lt;BR /&gt;Looks like SAS enhanced call execute to resolve the values at execution time (something like an implied call to the RESOLVE function).&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 18:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677096#M204217</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2020-08-16T18:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rerunning new %LET statements - easier way?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677097#M204218</link>
      <description>&lt;P&gt;The timing issue with call execute() and macros occurs when calling a macro that has logic that depends on macro variables that are generated/modified by the SAS code that the macro generates.&amp;nbsp; If you don't delay the macro call until after the data step execution has finished then the macro logic runs during the CALL EXECUTE() operation and makes it decisions about what code to generate before the generated SAS code has a chance to run and set/change the macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That does not apply in this case.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 18:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rerunning-new-LET-statements-easier-way/m-p/677097#M204218</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T18:12:09Z</dc:date>
    </item>
  </channel>
</rss>

