<?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: Using macrovariable path in filename error Invalid DO loop control information, either the INITI in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956398#M373475</link>
    <description>&lt;P&gt;I'm now using symget. I would like to run the macro with a call execute, so I will get a list of all the files in the folder. In the end some of these files would need to be deleted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've now created the full path in variable pathname in the dataset deletefolders, this also contains the pathname.&amp;nbsp; The deletefolder dataset has multiple folders listed with haveseq as sequence number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still getting the same error when using symget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro basefile3 ( haveseq, pathname );&lt;BR /&gt;data have_&amp;amp;haveseq;&lt;BR /&gt;rc=filename('xx',symget('pathname'));&lt;BR /&gt;did=dopen('xx');&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;run;&lt;BR /&gt;%mend basefile3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Deletefolders;&lt;BR /&gt;call execute(cats('%basefile3(',haveseq||','||pathname,')'));&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jan 2025 09:05:59 GMT</pubDate>
    <dc:creator>ydang</dc:creator>
    <dc:date>2025-01-17T09:05:59Z</dc:date>
    <item>
      <title>Using macrovariable path in filename error Invalid DO loop control information, either the INITIAL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956307#M373446</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a macrovariable in filename in a macro, but it gives error&amp;nbsp;NOTE: Argument 1 to function DNUM(0) at line 41 column 69 is invalid.&lt;BR /&gt;ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,&lt;BR /&gt;or invalid. File doesn't seem to open.&amp;nbsp; pathname is created earlier as&amp;nbsp;C:\Users\ydang\OneDrive - Prinses Maxima Centrum\CDM_share\Briga share\&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro basefile2 (pathname, haveseq );&lt;BR /&gt;%let path=cats(strip("&amp;amp;studypath"),strip("&amp;amp;pathname"));&lt;BR /&gt;data have1;&lt;BR /&gt;rc=filename('xx','&amp;amp;path');&lt;BR /&gt;did=dopen('xx');&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;run;&lt;BR /&gt;%put path;&lt;BR /&gt;%mend basefile2;&lt;/P&gt;&lt;P&gt;%basefile2 (01 Source\20230609,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine if I use:&lt;/P&gt;&lt;P&gt;rc=filename('xx',C:\Users\ydang\OneDrive - Prinses Maxima Centrum\CDM_share\Briga share\01 Source\20230609&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956307#M373446</guid>
      <dc:creator>ydang</dc:creator>
      <dc:date>2025-01-16T13:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956308#M373447</link>
      <description>You need to use double quotes around all macro variables, not single.  SAS will not resolve them otherwise.</description>
      <pubDate>Thu, 16 Jan 2025 13:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956308#M373447</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-16T13:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956309#M373448</link>
      <description>&lt;P&gt;There are several things to fix/understand in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Whatever value macrovariable PATH will have in this part:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=filename('xx','&amp;amp;path');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;macrovariable's value will NOT be resolved because single quoted text strings are not resolved by macroprocesor.&lt;/P&gt;
&lt;P&gt;Run this and see what will you get:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ABC = 123456789;

data _null_;
x = "&amp;amp;ABC.";
y = '&amp;amp;ABC.';

put x= ;
put y= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) when you are creating macrovariable PATH value you have the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=cats(strip("&amp;amp;studypath"),strip("&amp;amp;pathname"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;all that is considered by the macroprocesor as a text, so CATS and STRIP are not considered as functions but just ordinary text strings, so for example if STUDYPATH and PATHNAME would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let studyname=C:\directory1;
%let pathname=\directory2\directory3\;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;your final value of macrovariable PATH would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(strip("C:\directory1"),strip("\directory2\directory3\"))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;not as I guess you would like to have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;C:\directory1\directory2\directory3\&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW. use of STRIP is redundand since CATS already strips blank spaces (that's the "S" at the name)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) if you really would like to grab macrovariable's value in data step, instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=filename('xx',"&amp;amp;path");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;use SYMGET:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rc=filename('xx',symget('path'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it's much more robust solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And 4) just for clarity, what is your purpose? What do you want the cod to do? If you could describe it maybe the community could share better solution. Trust me SAS is old enough language (50+ years) to have majority of questions already answered (sometimes multiple times).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 13:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956309#M373448</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-01-16T13:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956398#M373475</link>
      <description>&lt;P&gt;I'm now using symget. I would like to run the macro with a call execute, so I will get a list of all the files in the folder. In the end some of these files would need to be deleted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've now created the full path in variable pathname in the dataset deletefolders, this also contains the pathname.&amp;nbsp; The deletefolder dataset has multiple folders listed with haveseq as sequence number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still getting the same error when using symget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro basefile3 ( haveseq, pathname );&lt;BR /&gt;data have_&amp;amp;haveseq;&lt;BR /&gt;rc=filename('xx',symget('pathname'));&lt;BR /&gt;did=dopen('xx');&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;run;&lt;BR /&gt;%mend basefile3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Deletefolders;&lt;BR /&gt;call execute(cats('%basefile3(',haveseq||','||pathname,')'));&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 09:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956398#M373475</guid>
      <dc:creator>ydang</dc:creator>
      <dc:date>2025-01-17T09:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956402#M373476</link>
      <description>&lt;P&gt;Add double quotation marks, but still getting same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ydang_0-1737105851190.png" style="width: 553px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103768i6AB16368BA024C81/image-dimensions/553x92?v=v2" width="553" height="92" role="button" title="ydang_0-1737105851190.png" alt="ydang_0-1737105851190.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro basefile6 ( haveseq, pathname );&lt;BR /&gt;data have_&amp;amp;haveseq;&lt;BR /&gt;rc=filename("xx",symget("pathname"));&lt;BR /&gt;did=dopen("xx");&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;rc=filename (did);&lt;BR /&gt;run;&lt;BR /&gt;%mend basefile6;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 09:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956402#M373476</guid>
      <dc:creator>ydang</dc:creator>
      <dc:date>2025-01-17T09:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956404#M373477</link>
      <description>&lt;P&gt;Double quotes without using symget worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro basefile ( haveseq, pathname );&lt;BR /&gt;data have_&amp;amp;haveseq;&lt;BR /&gt;rc=filename('xx',"&amp;amp;pathname");&lt;BR /&gt;did=dopen('xx');&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;rc=filename (did);&lt;BR /&gt;run;&lt;BR /&gt;%mend basefile;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 10:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956404#M373477</guid>
      <dc:creator>ydang</dc:creator>
      <dc:date>2025-01-17T10:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956409#M373480</link>
      <description>&lt;P&gt;Use &lt;A href="https://github.com/SASPAC/baseplus" target="_self"&gt;BasePlus package&lt;/A&gt; for that task, in particular macro called &lt;A href="https://github.com/SASPAC/baseplus/blob/main/baseplus.md#dirsandfiles-macro-6" target="_self"&gt;%DirsAndFiles()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Installation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename packages "/a/path/to/store/package";

filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
%include SPFinit;
filename SPFinit clear;

%installPackage(SPFinit BASEPLUS) 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Package use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* LOAD PACKAGE: */
filename packages "/a/path/to/store/package"; /* setup directory for packages */
%include packages(SPFinit.sas);                     /* enable the framework */

%loadPackage(BasePlus)


 /* USE PACKAGE: */

%dirsandfiles(C:\your\path\to\search\for,ods=work.result)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 11:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956409#M373480</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-01-17T11:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using macrovariable path in filename error Invalid DO loop control information, either the INITI</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956416#M373483</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472176"&gt;@ydang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm now using symget. I would like to run the macro with a call execute, so I will get a list of all the files in the folder. In the end some of these files would need to be deleted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've now created the full path in variable pathname in the dataset deletefolders, this also contains the pathname.&amp;nbsp; The deletefolder dataset has multiple folders listed with haveseq as sequence number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm still getting the same error when using symget.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro basefile3 ( haveseq, pathname );&lt;BR /&gt;data have_&amp;amp;haveseq;&lt;BR /&gt;rc=filename('xx',symget('pathname'));&lt;BR /&gt;did=dopen('xx');&lt;BR /&gt;do i=1 to dnum(did);&lt;BR /&gt;fname=dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;rc=dclose(did);&lt;BR /&gt;run;&lt;BR /&gt;%mend basefile3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set Deletefolders;&lt;BR /&gt;call execute(cats('%basefile3(',haveseq||','||pathname,')'));&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First point is fix the CALL EXECUTE call so that the macro execute AFTER the data step.&amp;nbsp; Wrap the macro triggers in %NRSTR() so that the call to the macro is pushed to run instead of the code the macro generates being pushed to run.&amp;nbsp; Also remove the || since you are already using CATS() to do the concatenation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute(cats('%nrstr(%basefile3)(',haveseq,',',pathname,')'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why make separate datasets for each folder?&amp;nbsp; Ditch the macro and just put the DOPEN(),DREAD() logic into a data step and make ONE dataset with all of the file names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DeleteFiles;
  set Deletefolders;
  rc = filename('xx',pathname);
  did=dopen('xx');
  if did then do;
    do filenum=1 to dnum(did);
      length fname $256 ;
      fname=dread(did,filenum);
      output;
    end;
    rc=dclose(did);
  end;
  else put 'WARNING: Unable to open ' pathname 'as a directory.';
  drop rc did;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to use a macro then perhaps use one like&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set deletefolders end=eof;
  if _n_=1 then call execute('%nrstr(%dirtree)(out=deletefiles,directory=');
  else call execute('|');
  call execute(pathname);
  if eof then call execute(')');
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add MAXDEPTH=1 to the macro call if you don't want it to recurse into subdirectories.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 14:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macrovariable-path-in-filename-error-Invalid-DO-loop/m-p/956416#M373483</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-17T14:12:02Z</dc:date>
    </item>
  </channel>
</rss>

