<?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: searching the folder is vacant or not if vacant then call the macro after 10sec  else import. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793708#M254425</link>
    <description>I have paste the code with the logs I hope it is readable now.&lt;BR /&gt;My problem is when code is calling the macro again and again from 2nd time Rc is comming NOT success.&lt;BR /&gt;THIS CODE WILL SEARCH A FOLDER IF ANY FILE IS PRESENT IN A FOLDER OR NOT, IFNOT THEN RUN THE PROGRAM AFTER 10SEC GAIN AND AGAIN.&lt;BR /&gt;IF ANY FILE FOUND THEN IMPORT THE CSV FILES.</description>
    <pubDate>Tue, 01 Feb 2022 09:31:30 GMT</pubDate>
    <dc:creator>ANIRBAN2</dc:creator>
    <dc:date>2022-02-01T09:31:30Z</dc:date>
    <item>
      <title>searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793580#M254370</link>
      <description>&lt;P&gt;%Macro sleep(SourcePath=);&lt;BR /&gt;%global rc name did mem_cnt did csv_count dnum;&lt;BR /&gt;%let csv_count=0;&lt;BR /&gt;%let ext=%str(csv);&lt;BR /&gt;%let rc=%sysfunc(filename(filrf, &amp;amp;SourcePath));&lt;/P&gt;&lt;P&gt;%if &amp;amp;rc=0 %then&lt;BR /&gt;%put SUCCESS;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;%put NO SUCCESS;&lt;BR /&gt;%end;&lt;BR /&gt;%let did=%sysfunc(dopen(&amp;amp;filrf));&lt;/P&gt;&lt;P&gt;%if &amp;amp;did=0 %then&lt;BR /&gt;%put CANT OPEN;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;%put OPENED;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;did.&amp;gt; 0 %then&lt;BR /&gt;%let mem_cnt= %sysfunc(dnum(&amp;amp;did.));&lt;/P&gt;&lt;P&gt;%if &amp;amp;mem_cnt. =0 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let x=%sysfunc(SLEEP(10, 1)));&lt;BR /&gt;&lt;STRONG&gt;%sleep(SourcePath=&amp;amp;sourcepath);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;/*%put "NO FILES IN THE FOLDER";*/&lt;BR /&gt;%end;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;/P&gt;&lt;P&gt;/*-------------*/&lt;BR /&gt;%PUT THERE ARE &amp;amp;mem_cnt. files in the DIR;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;mem_cnt.;&lt;/P&gt;&lt;P&gt;/*-------------*/&lt;BR /&gt;%let full_name=%qsysfunc(dread(&amp;amp;did., &amp;amp;i.));&lt;BR /&gt;%let name=%qscan(%qsysfunc(dread(&amp;amp;did, &amp;amp;i)), -1, .);&lt;/P&gt;&lt;P&gt;%if %str(csv)=%str(&amp;amp;name.) %then&lt;BR /&gt;%do;&lt;/P&gt;&lt;P&gt;/*-------------*/&lt;BR /&gt;%put CSV PRESENT;&lt;/P&gt;&lt;P&gt;proc import datafile="&amp;amp;sourcepath/&amp;amp;full_name" out=work.&amp;amp;i.&lt;BR /&gt;dbms=csv replace;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%sleep(SourcePath=/home/u60099960/ani);&lt;BR /&gt;%put &amp;amp;mem_cnt;&lt;BR /&gt;%put &amp;amp;name;&lt;BR /&gt;%put &amp;amp;rc;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOGS: After every 10sec&lt;/STRONG&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;68&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;69 %sleep(SourcePath=/home/u60099960/ani);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;SUCCESS&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;OPENED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;NO SUCCESS&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;OPENED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;NO SUCCESS&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;OPENED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;NO SUCCESS&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;OPENED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;NO SUCCESS&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;OPENED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;My Question when I am calling the&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;%sleep(SourcePath=&amp;amp;sourcepath) &lt;/STRONG&gt;after execution of sleep function then from the 2nd time rc is not equal 0 so its showing&amp;nbsp; NO success.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;My question is why from the 2nd time is showing no success.?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 09:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793580#M254370</guid>
      <dc:creator>ANIRBAN2</dc:creator>
      <dc:date>2022-02-01T09:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793669#M254397</link>
      <description>&lt;P&gt;Sorry, but your code is hardly readable. Please use "insert sas code" (running man icon) and past properly formatted code.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 06:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793669#M254397</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-02-01T06:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793686#M254408</link>
      <description>&lt;P&gt;Please describe in plain language what your macro is supposed to do.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 08:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793686#M254408</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T08:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793708#M254425</link>
      <description>I have paste the code with the logs I hope it is readable now.&lt;BR /&gt;My problem is when code is calling the macro again and again from 2nd time Rc is comming NOT success.&lt;BR /&gt;THIS CODE WILL SEARCH A FOLDER IF ANY FILE IS PRESENT IN A FOLDER OR NOT, IFNOT THEN RUN THE PROGRAM AFTER 10SEC GAIN AND AGAIN.&lt;BR /&gt;IF ANY FILE FOUND THEN IMPORT THE CSV FILES.</description>
      <pubDate>Tue, 01 Feb 2022 09:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793708#M254425</guid>
      <dc:creator>ANIRBAN2</dc:creator>
      <dc:date>2022-02-01T09:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793709#M254426</link>
      <description>My problem is when code is calling the macro again and again from 2nd time Rc is comming NOT success.&lt;BR /&gt;THIS CODE WILL SEARCH A FOLDER IF ANY FILE IS PRESENT IN A FOLDER OR NOT, IFNOT THEN RUN THE PROGRAM AFTER 10SEC GAIN AND AGAIN.&lt;BR /&gt;IF ANY FILE FOUND THEN IMPORT THE CSV FILES</description>
      <pubDate>Tue, 01 Feb 2022 09:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793709#M254426</guid>
      <dc:creator>ANIRBAN2</dc:creator>
      <dc:date>2022-02-01T09:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793716#M254433</link>
      <description>&lt;P&gt;You do not need a recursion, a simple %DO loop will do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro sleep(sourcepath=);
%local rc did count numfiles name; /* local to avoid side effects */
filename ___dir "&amp;amp;sourcepath.";
%let did = %sysfunc(dopen(___dir));
%if &amp;amp;did. = 0
%then %put Error opening directory;
%else %do;
  %let count = 0;
  %let numfiles = %sysfunc(dnum(&amp;amp;did.));
  %do %while (&amp;amp;count. le 3 and &amp;amp;numfiles. = 0);
    %let count = %eval(&amp;amp;count. + 1);
    %let numfiles = %sysfunc(dnum(&amp;amp;did.));
    %let rc = %sysfunc(sleep(10,1));
  %end;
  %if &amp;amp;numfile. gt 0
  %then %do i = 1 %to &amp;amp;numfiles.;
    %let name = %sysfunc(dread(&amp;amp;did.,&amp;amp;i.));
    proc import
      datafile="&amp;amp;sourcepath./&amp;amp;name."
      out=work.ds&amp;amp;i.
      dbms=csv
      replace
    ;
    run;
  %end;
  %else %put No files found;
  %let rc = %sysfunc(dclose(&amp;amp;did.)); /* always clean up */
%end;
%else %put Cannot open directory;
filename ___dir clear;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added a count to prevent infinite looping if the directory is never populated.&lt;/P&gt;
&lt;P&gt;Checking the return code of a FILENAME function is not necessary, as the function will always work (even if a file/directory does not exist, the fileref could be used to create it), so I used FILENAME statements.&lt;/P&gt;
&lt;P&gt;Cleaning up file/directory handles is necessary as they will accumulate otherwise.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 10:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793716#M254433</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T10:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793758#M254455</link>
      <description>THIS I COULD UNDERSTAND&lt;BR /&gt;THANKS.&lt;BR /&gt;BUT PLEASE CAN U IDENTIFY THE ERROR IN MY CODE</description>
      <pubDate>Tue, 01 Feb 2022 13:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793758#M254455</guid>
      <dc:creator>ANIRBAN2</dc:creator>
      <dc:date>2022-02-01T13:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: searching the folder is vacant or not if vacant then call the macro after 10sec  else import.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793813#M254470</link>
      <description>&lt;P&gt;I guess the culprit is your %GLOBAL statement, and it is not only not necessary, but dangerous. Use %LOCAL instead.&lt;/P&gt;
&lt;P&gt;Why? A variable defined as local to a macro will appear as global for all macros that are called from this macro anyway. By using %GLOBAL, you force the called macro to use the variable it inherited through the call, and it then manipulates a value that should have been kept as-is for the "outer" macro.&lt;/P&gt;
&lt;P&gt;All good macros take care to define all variables as local, unless an explicit side-effect is wanted, or the variables' contents are never changed in the macro.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 15:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/searching-the-folder-is-vacant-or-not-if-vacant-then-call-the/m-p/793813#M254470</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-01T15:06:01Z</dc:date>
    </item>
  </channel>
</rss>

