<?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: Check if the file exists inside of a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460997#M117208</link>
    <description>&lt;P&gt;Then I get&lt;/P&gt;
&lt;P&gt;ERROR: Required operator not found in expression: fileexist(work.to_&amp;amp;next_mon._&amp;amp;jahr.)&lt;/P&gt;</description>
    <pubDate>Wed, 09 May 2018 13:16:44 GMT</pubDate>
    <dc:creator>DrBoogie</dc:creator>
    <dc:date>2018-05-09T13:16:44Z</dc:date>
    <item>
      <title>Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460983#M117203</link>
      <description>&lt;P&gt;Hi all, I am trying now to set together several files, with this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro imp;
%let mon = jan feb mar apr mai jun jul aug sep okt nov dez;
data outtab;
set 
%do jahr=16 %to 18;
  %do i=1 %to %sysfunc(countw(&amp;amp;mon));
   %let next_mon = %scan(&amp;amp;mon, &amp;amp;i);
     work.to_&amp;amp;next_mon._&amp;amp;jahr.   
  %end;
%end;
;
run;
%mend;
&lt;/PRE&gt;
&lt;P&gt;It works fine. But it could be potentially a problem if one of the files doesn't exist. I want now to&amp;nbsp;incorporate a corresponding check. So I made this change:&lt;/P&gt;
&lt;PRE&gt;%macro imp;
%let mon = jan feb mar apr mai jun jul aug sep okt nov dez;
data outtab;
set 
%do jahr=16 %to 18;
  %do i=1 %to %sysfunc(countw(&amp;amp;mon));
   %let next_mon = %scan(&amp;amp;mon, &amp;amp;i);
     %if fileexist(to_&amp;amp;next_mon._&amp;amp;jahr.) %then work.to_&amp;amp;next_mon._&amp;amp;jahr.;   
  %end;
%end;
;
run;
%mend;
&lt;/PRE&gt;
&lt;P&gt;Unfortunately this doesn't work because %if fileexist is always FALSE although the files are available.&amp;nbsp;I guess that&amp;nbsp;%if fileexist&amp;nbsp;cannot be placed in the data step. But what is the alternative way? Do You have some idea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460983#M117203</guid>
      <dc:creator>DrBoogie</dc:creator>
      <dc:date>2018-05-09T12:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460984#M117204</link>
      <description>&lt;P&gt;Please see the FILEEXIST documentation&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n06xm8hwk0t0axn10gj16lfiri43.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n06xm8hwk0t0axn10gj16lfiri43.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They give an example of using FILEEXIST inside of a macro involving the use of macro function %SYSFUNC&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460984#M117204</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-05-09T12:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460985#M117205</link>
      <description>&lt;P&gt;For macro language to use FILEEXIST, try wrapping it up inside %SYSFUNC:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%if %sysfunc(fileexist(to_&amp;amp;next_mon._&amp;amp;jahr.)) %then work.to_&amp;amp;next_mon._&amp;amp;jahr.;   &lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 12:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460985#M117205</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-09T12:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460988#M117206</link>
      <description>&lt;P&gt;Make you life a lots easier (well less easy than not having like data in many different datasets in the first place) by having all your datasets either in one naming type, or in one libname.&amp;nbsp; For instance one way using code generation:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="TMP")) end=last;
  if _n_=1 then call execute('data want; set'); 
  call execute(' tmp.'||strip(memname));
  if last then call execute('; run;');
run;&lt;/PRE&gt;
&lt;P&gt;This will set every dataset in library tmp together - i.e. you don't need to do any calculation or checking the file exists.&amp;nbsp; You can also use lists:&lt;/P&gt;
&lt;PRE&gt;data want;
  set tmp.jan_: tmp.feb_:  ...;
run;&lt;/PRE&gt;
&lt;P&gt;Note the colon after the prefix, means everything with a prefix jan_ for example.&lt;/P&gt;
&lt;P&gt;Various methods of doing such a task, but should never really be needed as storing data out into small blocks with data (dates in this case) is no really a good storage method, very "Excel thinking".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 12:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460988#M117206</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-09T12:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460997#M117208</link>
      <description>&lt;P&gt;Then I get&lt;/P&gt;
&lt;P&gt;ERROR: Required operator not found in expression: fileexist(work.to_&amp;amp;next_mon._&amp;amp;jahr.)&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 13:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/460997#M117208</guid>
      <dc:creator>DrBoogie</dc:creator>
      <dc:date>2018-05-09T13:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461002#M117210</link>
      <description>&lt;P&gt;Thank You, it's&amp;nbsp; a nice idea, but then I have to be sure that there&amp;nbsp;are no other files in the library which is also not an optimal way for me.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 13:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461002#M117210</guid>
      <dc:creator>DrBoogie</dc:creator>
      <dc:date>2018-05-09T13:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461005#M117211</link>
      <description>&lt;P&gt;Yes, unfortunately with a bad storage solution, you will end up with bad processes.&amp;nbsp; Another way:&lt;/P&gt;
&lt;P&gt;- set all data together, using indsname to create a date variable for filtering&lt;/P&gt;
&lt;P&gt;- filter this dataset for the date ranges you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 13:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461005#M117211</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-09T13:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461008#M117213</link>
      <description>&lt;P&gt;"Yes, unfortunately with a bad storage solution, you will end up with bad processes"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yep. but I have no influence at all as for the storage solution. I am a very small person in a very large company. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 13:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461008#M117213</guid>
      <dc:creator>DrBoogie</dc:creator>
      <dc:date>2018-05-09T13:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461057#M117230</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4324"&gt;@DrBoogie&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Then I get&lt;/P&gt;
&lt;P&gt;ERROR: Required operator not found in expression: fileexist(work.to_&amp;amp;next_mon._&amp;amp;jahr.)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;FILEEXIST() is for physical&amp;nbsp; filenames.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test if a dataset exists using a one or two level name then use the EXIST() function instead.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 14:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461057#M117230</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-09T14:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461085#M117242</link>
      <description>&lt;P&gt;For SAS data set you need to use EXIST function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(exist(one-or-two-level-name))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 May 2018 15:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461085#M117242</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-05-09T15:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Check if the file exists inside of a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461184#M117279</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 20:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-the-file-exists-inside-of-a-macro/m-p/461184#M117279</guid>
      <dc:creator>DrBoogie</dc:creator>
      <dc:date>2018-05-09T20:31:52Z</dc:date>
    </item>
  </channel>
</rss>

