<?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: Include statement in macro not recognising file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487711#M287323</link>
    <description>&lt;P&gt;If&amp;nbsp;it's able to look for new files I imagine the On New File trigger could work for what I'm doing. If&amp;nbsp;I can't make the code above work I'll look into that, thanks for the tip!&amp;nbsp;To clarify, it's an ongoing list of raw files sat&amp;nbsp;in the SFTP, they get added to every day with data from the previous day. The code will take only the latest data,&amp;nbsp;manipulate&amp;nbsp;it&amp;nbsp;as desired and then append it into another dataset. Processing everything at once would take ages so isn't suitable for a daily job.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Aug 2018 11:01:10 GMT</pubDate>
    <dc:creator>PatrickBros1993</dc:creator>
    <dc:date>2018-08-17T11:01:10Z</dc:date>
    <item>
      <title>Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487673#M287315</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Update();

%global Updated MaxDate;
%include 'Y:\Marketing\mi_analysis\Reports\04.Digital\Revised Digital Reporting\01 Code\Tidied\02a - Data Load.sas';

%if &amp;amp;NewFiles.=0 %then %do;
	%do %until(&amp;amp;LastRun.=1);

	data _null_;
 	x = sleep(900);
 	run;

	data now;
	format now hhmm.;
	now=time();
	if now&amp;gt;='09:15't then LastRun=1; else LastRun=0;
	call symput('now',now);
	call symput('LastRun',LastRun);
	run;

	%put  &amp;amp;now;
	%put  &amp;amp;LastRun;

	%include 'Y:\Marketing\mi_analysis\Reports\04.Digital\Revised Digital Reporting\01 Code\Tidied\02a - Data Load.sas';
	
	%if &amp;amp;NewFiles.&amp;gt;0 %then %do;
	%let LastRun=1;
	%end;
	%else %do;
	%end;

	%end;
%end;
%else %do;
%end;


%if &amp;amp;NewFiles.=0 %then %do;
%email("my email address","Files not arrived");
%end;
%else %do;
%end;


%mend;

%Update();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have some code here which is meant to load in a series of CSV files each morning from an SFTP folder. I've written a macro so that it runs once, and if the files haven't yet arrived then it will wait 15 minutes and try again, and repeats this as such until a specified time (9:15) when it stops and sends out an email notifying the files haven't arrived. This seems to work fine when I run it in from a session, but run from the scheduler it keeps failing on the 'do until' loop - I get&amp;nbsp;the following message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WARNING: Physical file does not exist, Y:\Marketing\mi_analysis\Reports\04.Digital\Revised Digital&lt;BR /&gt;Reporting\01 Code\Tidied\02a - Data Load.sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is quite frustrating as it recognises the file and runs&amp;nbsp;on the initial %include statement, and the second include statement is a copy and paste of the first so it's definitely not a typo or anything. I'm guessing it might be something to do with the fact it's in&amp;nbsp;that conditional part of the macro&amp;nbsp;which is causing a problem. Does anyone have any ideas?? As mentioned before it's only when run from the scheduler that this occurs (I don't know much about the technical details of this scheduler but if it's relevant I can ask).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487673#M287315</guid>
      <dc:creator>PatrickBros1993</dc:creator>
      <dc:date>2018-08-17T08:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487677#M287316</link>
      <description>&lt;P&gt;Probably the scheduler does not have access to that network or path.&amp;nbsp; The error is pretty clear in that it can't find the file, so your scheduler person is the one to ask.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a note, if you have a scheduler program/person, why not ask them if there is an On File Received trigger, rather than waiting around re-scanning every few minutes your end, have a trigger that calls your import program only when a new file is received.&amp;nbsp; That would be my preferred solution.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 08:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487677#M287316</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-17T08:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487680#M287317</link>
      <description>&lt;P&gt;Thanks, I'm also waiting for a reply from the SAS administrators.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that all the historic files are sat on that SFTP, so rather than looking for the presence of a file(s) it needs to look specifically for the presence of the latest files containing data for the days since the last time the code was run. That means it has to run the import program which selects only the latest files.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 09:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487680#M287317</guid>
      <dc:creator>PatrickBros1993</dc:creator>
      <dc:date>2018-08-17T09:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487681#M287318</link>
      <description>&lt;P&gt;How can you be sure that the first %include works, but not the second?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 09:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487681#M287318</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-17T09:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487682#M287319</link>
      <description>Because the logs show it runs the first statement fine, then when it goes into the do until loop I get the aforementioned error every time it tries the include statement.</description>
      <pubDate>Fri, 17 Aug 2018 09:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487682#M287319</guid>
      <dc:creator>PatrickBros1993</dc:creator>
      <dc:date>2018-08-17T09:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487685#M287320</link>
      <description>&lt;P&gt;But the file is a new file which appears on there?&amp;nbsp; Or do you mean all the data is there now and you are only importing a bit of it at a time?&amp;nbsp; If its a new file, then you just need an On New File trigger.&amp;nbsp; If all the data is there, then why not just import it all now to datasets and be done with it?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 09:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487685#M287320</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-17T09:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487691#M287321</link>
      <description>&lt;P&gt;Then there are two possibilities as far as I can see:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;something causes the path to the file to go "missing" (change in permission, unmount the share, ....)&lt;/LI&gt;
&lt;LI&gt;you are mis-reading the log. Macro timing can be very tricky.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Add %put statements frequently, so you can follow all the possible execution paths. Set options source2, so you can see all the code from the includes in the log.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 09:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487691#M287321</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-17T09:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487699#M287322</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200757"&gt;@PatrickBros1993&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;So if this runs fine out of your session but not when scheduled then I'd look out for two things first:&lt;/P&gt;
&lt;P&gt;1. Permissions&lt;/P&gt;
&lt;P&gt;Your session will run under your user while the scheduled job will run under a batch user. If this user doesn't have access to the file (doesn't "see" it) then you could get such an error.&lt;/P&gt;
&lt;P&gt;2. Timing&lt;/P&gt;
&lt;P&gt;You say the 2nd include is a copy of the file. When does this copy happen? I don't believe this applies to your problem but I've seen cases where a scheduled batch process got trigger "on file arrival" but then the process failed because the SFTP process creating the file hadn't finished yet - so the file "arrived" but wasn't fully available yet when the process consuming the data got triggered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 10:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487699#M287322</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-08-17T10:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Include statement in macro not recognising file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487711#M287323</link>
      <description>&lt;P&gt;If&amp;nbsp;it's able to look for new files I imagine the On New File trigger could work for what I'm doing. If&amp;nbsp;I can't make the code above work I'll look into that, thanks for the tip!&amp;nbsp;To clarify, it's an ongoing list of raw files sat&amp;nbsp;in the SFTP, they get added to every day with data from the previous day. The code will take only the latest data,&amp;nbsp;manipulate&amp;nbsp;it&amp;nbsp;as desired and then append it into another dataset. Processing everything at once would take ages so isn't suitable for a daily job.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 11:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Include-statement-in-macro-not-recognising-file/m-p/487711#M287323</guid>
      <dc:creator>PatrickBros1993</dc:creator>
      <dc:date>2018-08-17T11:01:10Z</dc:date>
    </item>
  </channel>
</rss>

