<?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: Resolving a macro name in same data step up in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736708#M229557</link>
    <description>&lt;P&gt;Sorry, just glanced at it now, the value (second argument) in the SYMPUT call routine should be "file_name" and not "filename".&lt;/P&gt;</description>
    <pubDate>Sat, 24 Apr 2021 03:53:29 GMT</pubDate>
    <dc:creator>qoit</dc:creator>
    <dc:date>2021-04-24T03:53:29Z</dc:date>
    <item>
      <title>Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736693#M229548</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read in all .sas file from one location and then put in another file so I can run this file as batch file. I am creating a macro variable filename which is not getting resolved in the "put" statement below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename inprog pipe 'dir C:\test\*.sas /b';&lt;BR /&gt;filename dbatch "C:\test2\dbatch.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;infile inprog truncover;&lt;BR /&gt;input file_name $32.;&lt;BR /&gt;call execute ('data _null_ ; infile inprog truncover; input file_name $32. ; &lt;FONT color="#FF0000"&gt;call symput("filename",filename)&lt;/FONT&gt; ; run;' );&lt;/P&gt;&lt;P&gt;file dbatch;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;put '%include ' '"C:\test2\&amp;amp;filename." ' ';' ;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Apr 2021 23:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736693#M229548</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2021-04-23T23:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736695#M229550</link>
      <description>&lt;P&gt;You're not understanding when the CALL EXECUTE will actually be processed. It generates all the code, but it doesn't actually execute anything until the end of the data step. Your PUT statement doesn't have the value accessible to execute it. Some workarounds include:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Move the PUT to also be in a CALL EXECUTE()&lt;/LI&gt;
&lt;LI&gt;Switch DOSUBL&lt;/LI&gt;
&lt;LI&gt;Generate the list of file names ahead of time somehow and then do what ever you want next.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Did you know that %INCLUDE can be wild carded?&lt;/P&gt;
&lt;P&gt;So you can use the code below to run all SAS scripts in a folder as well. Not sure why you're copying them from one location to another but you may want to look into FCOPY() instead of reading/re-writing the files. That forces you to process a file entirely, whereas FCOPY is a bulk move and should be faster.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include 'path to folder/*.sas';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91198"&gt;@Leo9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to read in all .sas file from one location and then put in another file so I can run this file as batch file. I am creating a macro variable filename which is not getting resolved in the "put" statement below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename inprog pipe 'dir C:\test\*.sas /b';&lt;BR /&gt;filename dbatch "C:\test2\dbatch.sas";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;infile inprog truncover;&lt;BR /&gt;input file_name $32.;&lt;BR /&gt;call execute ('data _null_ ; infile inprog truncover; input file_name $32. ; &lt;FONT color="#FF0000"&gt;call symput("filename",filename)&lt;/FONT&gt; ; run;' );&lt;/P&gt;
&lt;P&gt;file dbatch;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;put '%include ' '"C:\test2\&amp;amp;filename." ' ';' ;&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 00:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736695#M229550</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-24T00:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736698#M229551</link>
      <description>&lt;P&gt;If I get that right and you just want to create a new file with %include statements then below code should do the job for you.&lt;/P&gt;
&lt;P&gt;I've changed your inprog filename a bit so it hopefully can also deal with Windows paths that include folder names with blanks in the name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let source_dir=C:\test;
filename inprog pipe "dir ""%str(&amp;amp;source_dir)""\*.sas /b";
filename dbatch "C:\test2\dbatch.sas";

data _null_;
  infile inprog truncover;
  input file_name $32.;
/*  file print;*/
  file dbatch;
  put '%include "' "%str(&amp;amp;source_dir)/" _infile_ '"/source2;';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Apr 2021 00:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736698#M229551</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-24T00:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736708#M229557</link>
      <description>&lt;P&gt;Sorry, just glanced at it now, the value (second argument) in the SYMPUT call routine should be "file_name" and not "filename".&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 03:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736708#M229557</guid>
      <dc:creator>qoit</dc:creator>
      <dc:date>2021-04-24T03:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736721#M229561</link>
      <description>&lt;P&gt;The CALL EXECUTE (which only repeats your DATA _NULL_ step multiple times, always keeping the last filename in the macro variable) is not needed at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile inprog truncover;
file dbatch;
input file_name $32.;
lenght line $50;
line = cats("%include 'C:\test2\",file_name,"'");
put line;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;EM&gt;Edit: added quotes around the pathname&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 19:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736721#M229561</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-24T19:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736757#M229588</link>
      <description>&lt;P&gt;Why do you want to create the macro variable?&amp;nbsp; The current data step already has the value in a real variable.&amp;nbsp; Probably easiest to just use DATA step code to prefix the directory name.&amp;nbsp; Use the $QUOTE format to have the value printed with quotes for the %INCLUDE statement generation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile inprog truncover;
  input file_name $256. ;
  file_name = cats('C:\test1\',filename);
  file dbatch;
  put '%include ' file_name :$quote. ';' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Apr 2021 16:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/736757#M229588</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-24T16:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving a macro name in same data step up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/737130#M229762</link>
      <description>&lt;P&gt;Thank you all who responded, appreciate it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 22:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-name-in-same-data-step-up/m-p/737130#M229762</guid>
      <dc:creator>Leo9</dc:creator>
      <dc:date>2021-04-26T22:40:26Z</dc:date>
    </item>
  </channel>
</rss>

