<?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: create blank file or empty contents of file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792473#M253909</link>
    <description>&lt;P&gt;We need to see the whole log, so we can also check the creation of macro variable &amp;amp;did.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 14:02:57 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-01-26T14:02:57Z</dc:date>
    <item>
      <title>create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792440#M253897</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I check a directory to see if there are files. If there are no files I create a csv file in it however when creating the file it populates the results of checking the directory. Is there a way to create an empty file or empty the contents of my csv file?&lt;/P&gt;&lt;PRE&gt;data _null_ ;
filename pathdir "%C:/FileCheck";
did = dopen("pathdir");
numfiles =dnum(did);
rc = dclose(did);
run;

%if(&amp;amp;did = 0) %then %do;
proc export 
    outfile="C:/Log.csv" 
    dbms=tab;
run;
%end;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 12:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792440#M253897</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-01-26T12:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792450#M253900</link>
      <description>&lt;P&gt;Use the same technique I showed you &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Automate-file-names/m-p/792400/highlight/true#M81494" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;A simple FILE statement without a PUT creates an empty file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file "C:/Log.csv";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jan 2022 12:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792450#M253900</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-26T12:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792454#M253901</link>
      <description>Hi I tried that but got an error:&lt;BR /&gt;ERROR: Extension for physical file name "C:/Log.csv" does not correspond to a valid member type.&lt;BR /&gt;&lt;BR /&gt;code:&lt;BR /&gt;%if(&amp;amp;did = 0) %then %do;&lt;BR /&gt;data _null_&lt;BR /&gt;file "C:/Log.csv" ;&lt;BR /&gt;run;&lt;BR /&gt;%end;</description>
      <pubDate>Wed, 26 Jan 2022 13:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792454#M253901</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-01-26T13:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792457#M253904</link>
      <description>&lt;P&gt;The data _null_ statement misses the semicolon.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 13:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792457#M253904</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-26T13:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792459#M253905</link>
      <description>After adding the semicolon it gives this error:&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;(&amp;amp;did = 0)&lt;BR /&gt;ERROR: Skipping to next %END statement.</description>
      <pubDate>Wed, 26 Jan 2022 13:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792459#M253905</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-01-26T13:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792473#M253909</link>
      <description>&lt;P&gt;We need to see the whole log, so we can also check the creation of macro variable &amp;amp;did.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 14:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792473#M253909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-26T14:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: create blank file or empty contents of file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792483#M253917</link>
      <description>&lt;P&gt;Your current program appears to be running a data step to check if a directory exists.&lt;/P&gt;
&lt;P&gt;It then tests some un-related macro variable that you don't show where it came from to decide whether or not to run PROC EXPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot tell from your question what you actually want to happen.&amp;nbsp; If the dataset has zero observations then PROC EXPORT will not create an empty file. It will write a file that only contain the header row.&amp;nbsp; So not empty, just one with zero lines of actual data.&amp;nbsp; Is the goal to not write that header line?&amp;nbsp; &amp;nbsp;Is the goal to not create the file at all?&amp;nbsp; What about if there was already a file at that location? Do you want to erase the existing file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is the question about the logic errors in your program (you are referencing a macro variable named DID that you never created).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or the call to the macro named C that you have not provided any definition for.&amp;nbsp; Or is that just a typo.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are using C: in filenames implying WINDOWS/DOS operating system but then using / as the delimiter between the directories instead of \.&amp;nbsp; (Note: SAS will silently fix the / for you converting them into \ when actually reading/writing from the Windows filesystem).&amp;nbsp; Is that part of the issue or just typos when making dummy names to share on-line?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Here is a simple macro to test if a directory exists:&amp;nbsp; &lt;A href="https://github.com/sasutils/macros/blob/master/direxist.sas" target="_self"&gt;%direxist()&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;So perhaps you want to run something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %direxist(/some/directory/) %then %do;
proc export 
    outfile="/some/file" 
    dbms=tab;
run;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: A CSV file is a Comma Separated Values file.&amp;nbsp; If you are going to use TAB as your delimiter you might want to use a different extension on the filename.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 14:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-blank-file-or-empty-contents-of-file/m-p/792483#M253917</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-26T14:38:33Z</dc:date>
    </item>
  </channel>
</rss>

