<?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 Read CSV file and check file exist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940528#M369155</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a CSV file contains these data, the first column is a path to a file:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;"D:\SAS\testfile.txt","Windows"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;"HOST.ABC.COBOL(FILE1)","Mainframe"&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I have SAS code to read the CSV file and check the first column to see if the the file exist, even though the CSV file has 2 records, I only see 1 output in the log, and the output always 0.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data work.input;
  	length DataSet $ 50 System $ 50;
  	infile 'D:\SAS\inputdata.csv' end=eof dlm=',' dsd firstobs=2 truncover;
	do while (not eof);
  		input DataSet $  MALCode $ System $;	
		%let dsid = %sysfunc(fileexist(DataSet));
		%put &amp;amp;dsid;
	end;
  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the end, if the file exist, then I want to keep the record read from CSV file, else then don't keep the record. Hope someone can help point me to the right direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Aug 2024 19:06:47 GMT</pubDate>
    <dc:creator>BladeStorm</dc:creator>
    <dc:date>2024-08-22T19:06:47Z</dc:date>
    <item>
      <title>Read CSV file and check file exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940528#M369155</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a CSV file contains these data, the first column is a path to a file:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;"D:\SAS\testfile.txt","Windows"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;"HOST.ABC.COBOL(FILE1)","Mainframe"&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I have SAS code to read the CSV file and check the first column to see if the the file exist, even though the CSV file has 2 records, I only see 1 output in the log, and the output always 0.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data work.input;
  	length DataSet $ 50 System $ 50;
  	infile 'D:\SAS\inputdata.csv' end=eof dlm=',' dsd firstobs=2 truncover;
	do while (not eof);
  		input DataSet $  MALCode $ System $;	
		%let dsid = %sysfunc(fileexist(DataSet));
		%put &amp;amp;dsid;
	end;
  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the end, if the file exist, then I want to keep the record read from CSV file, else then don't keep the record. Hope someone can help point me to the right direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 19:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940528#M369155</guid>
      <dc:creator>BladeStorm</dc:creator>
      <dc:date>2024-08-22T19:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file and check file exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940530#M369157</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid = %sysfunc(fileexist(DataSet));
%put &amp;amp;dsid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;These are macro statements, which are resolved when the macro triggers are encountered while the code is fetched for compilation. So the FILEEXIST function looks for a file named "Dataset" in the current working directory of the SAS process, which does not exist.&lt;/P&gt;
&lt;P&gt;Use data step code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.input;
length DataSet $ 50 System $ 50;
infile 'D:\SAS\inputdata.csv' dlm=',' dsd firstobs=2 truncover;
input DataSet $  MALCode $ System $;	
dsid = fileexist(DataSet);
if dsid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is also no need for the DO WHILE, the DATA step loops on itself when it has an INPUT or other statement that reads data.&lt;/P&gt;
&lt;P&gt;This also allows use of a Subsetting IF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 19:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940530#M369157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-22T19:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV file and check file exist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940532#M369159</link>
      <description>&lt;P&gt;You are amazing Kurt_Bremser, your suggestion works well, thank you so much.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 19:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-CSV-file-and-check-file-exist/m-p/940532#M369159</guid>
      <dc:creator>BladeStorm</dc:creator>
      <dc:date>2024-08-22T19:39:08Z</dc:date>
    </item>
  </channel>
</rss>

