<?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: Macro for path and list of files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816713#M322397</link>
    <description>&lt;P&gt;In your previous thread, I and others specifically asked to see the log (all of it) after you turn on the option to debug macros. Please follow those instructions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first question: you need double quotes, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename indata pipe "dir P:\Results\RFs\&amp;amp;d./b";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput ("num_files_&amp;amp;d._rf",_n_);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 19:06:47 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-06T19:06:47Z</dc:date>
    <item>
      <title>Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816705#M322390</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro fileread_rf(d);

filename indata pipe 'dir P:\Results\RFs\&amp;amp;d./b';
/*to read the name of files in a folder*/
data file_list_&amp;amp;d._rf;
length fname_rf $50;
infile indata truncover;
input fname_rf $50.;
call symput ('num_files_&amp;amp;d._rf',_n_);
run;

%do j=1 %to &amp;amp;&amp;amp;num_files_&amp;amp;d._rf;
data _null_;
set file_list_&amp;amp;d._rf;
if _n_=&amp;amp;j;
call symput ('filein_rf',fname_rf);
run;

proc import file="P:\Results\RFs\&amp;amp;d.\&amp;amp;filein_rf"
out=rf_&amp;amp;d._&amp;amp;j.
dbms=csv;
run;

%end;
%mend fileread_rf; 
%fileread_rf(ALG);
%fileread_rf(MAT);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am sure there are more problems in my macro but for now i am struggling with two of them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. "&lt;CODE class=" language-sas"&gt;filename indata pipe 'dir P:\Results\RFs\&amp;amp;d./b'"&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I think this statement is wrong because when i run it I don't get the list of files in ALG or MAT folders.&lt;/P&gt;
&lt;P&gt;2. &lt;CODE class=" language-sas"&gt;num_files_&amp;amp;d._rf&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I am also gettung error for this statement. ERROR: Symbolic variable name NUM_FILES_&amp;amp;D._RF must contain only letters, digits, and underscores&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;could you please help me to fix it?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816705#M322390</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-06-06T18:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816711#M322395</link>
      <description>&lt;P&gt;&lt;STRONG&gt;The macro processor will ignore macro code that is embedded in strings bounded by single quotes.&lt;/STRONG&gt; Use double quote characters instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename indata pipe "dir P:\Results\RFs\&amp;amp;d. /b";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Do not use the ANCIENT function CALL SYMPUT().&lt;/STRONG&gt;&amp;nbsp; The only time you should EVER use that is if it is REQUIRED that the generated macro variable has leading and/or trailing spaces in it.&amp;nbsp; Use the normal CALL SYMPUTX() function instead.&amp;nbsp; And do not try to use an &amp;amp; character in the name of the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx("num_files_&amp;amp;d._rf",_n_);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816711#M322395</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T18:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816712#M322396</link>
      <description>&lt;P&gt;You have an problem&amp;nbsp; the macro variable &amp;amp;d will not resolve inside single quotes.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;filename indata pipe 'dir P:\Results\RFs\&amp;amp;d./b';

call symput ('num_files_&amp;amp;d._rf',_n_);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As previously suggested: Options Mprint and show the entire log when you get error messages. Copy the text from the log, open a text box on the forum and PASTE the text .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of looping over dataset that way look at the CALL EXECUTE statement in the data set syntax.&lt;/P&gt;
&lt;P&gt;Or write code statements to a program file and use %include to execute the statements.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 18:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816712#M322396</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-06T18:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816713#M322397</link>
      <description>&lt;P&gt;In your previous thread, I and others specifically asked to see the log (all of it) after you turn on the option to debug macros. Please follow those instructions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first question: you need double quotes, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename indata pipe "dir P:\Results\RFs\&amp;amp;d./b";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symput ("num_files_&amp;amp;d._rf",_n_);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816713#M322397</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-06T19:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816717#M322398</link>
      <description>&lt;P&gt;Do all of the CSV files with similar names have the same structure?&amp;nbsp; Same set of variables in the same order.&lt;/P&gt;
&lt;P&gt;If so then you can just read them all at once into ONE dataset.&amp;nbsp; This will eliminate your earlier problem where you were trying to modify the generated datasets.&lt;/P&gt;
&lt;P&gt;Here is a sketch.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rf_&amp;amp;d ;
  length fname filename $200;
  input "P:\Results\RFs\&amp;amp;d.\*" dsd truncover filename=fname;
  input @ ;
* Reset line counter and skip the header line ;
  if fname ne lag(fname) then do;
      number=0;
      delete ;
  end;
  filename = scan(fname,-1,'/\');
  number+1;
  input ..... ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just complete the INPUT statement to read in the variables. Add a FORMAT statement if some of the variable need to have special formats attached to display properly, normally only needed for DATE, TIME or DATETIME values.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816717#M322398</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T19:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816721#M322399</link>
      <description>&lt;P&gt;First error is because your file path with the macro variable reference needs to be in double quotes.&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp;filename indata pipe "dir P:\Results\RFs\&amp;amp;d./b";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second error, looks like you are trying to create a single macro variable named&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;NUM_FILES_&amp;amp;D._RF&lt;/STRONG&gt;, based on your CALL SYMPUT&amp;nbsp; statement and that is not proper naming.&amp;nbsp; If you mean for the &amp;amp;D to resolve to create a macro variable NUM_FILES_ALG_RF, you must use double quotes on you CALL SYMPUT&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2. call symput ("num_files_&amp;amp;d._rf",_n_);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 19:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/816721#M322399</guid>
      <dc:creator>JOL</dc:creator>
      <dc:date>2022-06-06T19:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro for path and list of files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/817666#M322748</link>
      <description>&lt;P&gt;You could do this without PIPE or XCMD, in a platform agnostic way - see:&amp;nbsp;&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__dirlist_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__dirlist_8sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2022 13:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-for-path-and-list-of-files/m-p/817666#M322748</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-06-12T13:43:08Z</dc:date>
    </item>
  </channel>
</rss>

