<?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: Failure to import csv data using fileexist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833405#M329453</link>
    <description>Sorry I meant to write the DATE is not a numeric format that I am applying to the FirstName or LastName variable but a variable of itself that I am applying the Date9. format to.</description>
    <pubDate>Wed, 14 Sep 2022 18:58:30 GMT</pubDate>
    <dc:creator>mmaleta851</dc:creator>
    <dc:date>2022-09-14T18:58:30Z</dc:date>
    <item>
      <title>Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833212#M329368</link>
      <description>&lt;P&gt;So I am working a project in SAS Enterprise Guide that pull daily data from a server, imports a csv with monthly data, appends the daily data to the monthly data, and re-saves the monthly csv to be used for analysis and to be pulled again the following day. The program I am having issues with is the program that imports the monthly CSV. The program is supposed to work as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let path=C:\\;



%macro import_date;
%if %sysfunc(fileexist(&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv))
%then %do;
data work.import;
	infile "&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv" dsd firstobs=2;
	informat PlayerId 8. FirstName LastName 'Market (Marketing)'n $40.  Date Date9. Sales;
	format PlayerId 8. FirstName LastName 'Market (Marketing)'n Date Date9. Sales;
	input PlayerId FirstName $ LastName $ 'Market (Marketing)'n  $ Date Sales;
run;
%end;
%else %do;
data work.import;
run;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It checks to see if the the monthly csv file exists in the path. If it does it is supposed to pull that file in order to be appended to the daily data set. If not, it creates a blank data set to append to. The program does run, but when the end result says "'work.import' does not exist. You will need to refresh the task that created it before it can be opened." However, when I isolate the data step and run it, and then re-run the entire program, it pulls the csv file. Any idea of what I am doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 18:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833212#M329368</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-13T18:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833224#M329380</link>
      <description>&lt;P&gt;First thing would be to check what the actual file name is that you pass to the Fileexist function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example when I extract just the part of the code that creates the name:&lt;/P&gt;
&lt;PRE&gt;%let path=C:\\;

%let result =&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv;
&lt;/PRE&gt;
&lt;P&gt;I get&lt;/P&gt;
&lt;PRE&gt;4    %put result is:&amp;amp;result;
result is:C:\\\Historical SEP2022  .csv
&lt;/PRE&gt;
&lt;P&gt;I question your definition of Path with 2 slashes to begin with but you add another in the file name.&lt;/P&gt;
&lt;P&gt;The space between "Historical" and %sysfunc means that there is a space in the resulting name. Again the spaces before the ".csv" means there are two spaces in the file name before .csv;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the filename does not resolve correctly then the Fileexist returns 0 and is false, so nothing happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When a MACRO misbehaves try running the code with OPTIONS MPRINT SYMBOLGEN; to see details of the generated code in the log. Symbolgen will provide a trace of how macro variables resolve to create a result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 19:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833224#M329380</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-13T19:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833227#M329382</link>
      <description>&lt;P&gt;It might help if the data step did not have conflicting definitions for some of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You force SAS to guess that FIRSTNAME and LASTNAME should be character variables and guess that the length should be 40 bytes.&amp;nbsp; But then you try to attach the numeric format DATE to the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also might help to define the filename in just one place, to avoid possible inconsistency.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fname=&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv;

data work.import;
	length PlayerId 8 FirstName LastName 'Market (Marketing)'n $40 Date Sales 8;
	format Date Date9.;
%if %sysfunc(fileexist(&amp;amp;fname)) %then %do;
	infile "&amp;amp;fname" dsd firstobs=2;
	input PlayerId FirstName LastName 'Market (Marketing)'n  Date :date. Sales;
%end;
%else %do;
    stop;
%end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dose the filename actually have all of those spaces before the .csv ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 19:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833227#M329382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-13T19:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833391#M329445</link>
      <description>&lt;P&gt;The %let path=C\\; is just a placeholder for the file path I use not my actual file path..&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 18:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833391#M329445</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T18:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833394#M329446</link>
      <description>&lt;P&gt;That solution wouldn't work for me. Whenever there is a new month I need to create a blank dataset for the new month so I can add the data for the first day of the month to that dataset and have that be the dataset. The point of the project is to accumulate daily data into monthly groups so it can be used externally for analysis.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 18:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833394#M329446</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T18:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833397#M329447</link>
      <description>&lt;P&gt;Additionally, DATE is not a numeric but date at which each instance occurred.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 18:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833397#M329447</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T18:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833403#M329452</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377271"&gt;@mmaleta851&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Additionally, DATE is not a numeric but date at which each instance occurred.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have not the slightest idea what you are talking about.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the DATE variable is not a number then why did you attach the numeric DATE9. format specification to it in the data step?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 18:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833403#M329452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-14T18:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833405#M329453</link>
      <description>Sorry I meant to write the DATE is not a numeric format that I am applying to the FirstName or LastName variable but a variable of itself that I am applying the Date9. format to.</description>
      <pubDate>Wed, 14 Sep 2022 18:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833405#M329453</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T18:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833408#M329455</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377271"&gt;@mmaleta851&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry I meant to write the DATE is not a numeric format that I am applying to the FirstName or LastName variable but a variable of itself that I am applying the Date9. format to.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But this is NOT what the posted code was doing.&lt;/P&gt;
&lt;P&gt;The code looked something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format A B date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which means attach the DATE9. format specification to all of the variables listed before it, so to both A and B.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 19:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833408#M329455</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-14T19:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833409#M329456</link>
      <description>I see what the issue is. I forgot to put $40 in between 'Market (Marketing)'n and Date in the format step. I apologize.&lt;BR /&gt;&lt;BR /&gt;Still even including this, the file does not export.</description>
      <pubDate>Wed, 14 Sep 2022 19:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833409#M329456</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T19:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833413#M329459</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377271"&gt;@mmaleta851&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I see what the issue is. I forgot to put $40 in between 'Market (Marketing)'n and Date in the format step. I apologize.&lt;BR /&gt;&lt;BR /&gt;Still even including this, the file does not export.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you mean EXPORT?&amp;nbsp; There is no EXPORT in the code you posted.&amp;nbsp; It was just a step to create a dataset that was named IMPORT.&amp;nbsp; The only conditional part was whether or not it would do that by reading from a CSV file or not.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 19:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833413#M329459</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-14T19:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833418#M329461</link>
      <description>&lt;P&gt;When I run the task, it runs but the resulting datafile says:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"WORK.IMPORT" does not exist. You will need to refresh the task that created it before it can be opened.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 19:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833418#M329461</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T19:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833419#M329462</link>
      <description>&lt;P&gt;Add the options&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option mprint symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and post the log with the full error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 19:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833419#M329462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-14T19:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833420#M329463</link>
      <description>Hey Reeza,&lt;BR /&gt;&lt;BR /&gt;I am using SAS EG. To run that option, do I include that in my code or do I use the options menu?</description>
      <pubDate>Wed, 14 Sep 2022 19:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833420#M329463</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T19:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833423#M329466</link>
      <description>&lt;P&gt;Include it in your code before the macro code and macro call.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 19:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833423#M329466</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-14T19:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833427#M329470</link>
      <description>&lt;P&gt;Gotcha.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included that before the code and got a log of SASWORKLOCATION but nothing else.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 20:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833427#M329470</guid>
      <dc:creator>mmaleta851</dc:creator>
      <dc:date>2022-09-14T20:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833430#M329472</link>
      <description>&lt;P&gt;Did you call the macro as well? There's nothing in the code shown that actually calls the macro so you may need to add that in as well if it's somewhere else in the process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\\;

options mprint symbolgen mlogic;

%macro import_date;
%if %sysfunc(fileexist(&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv))
%then %do;
data work.import;
	infile "&amp;amp;path\Historical %sysfunc(intnx(day, %sysfunc(today()), -1, s), monyy7.)  .csv" dsd firstobs=2;
	informat PlayerId 8. FirstName LastName 'Market (Marketing)'n $40.  Date Date9. Sales;
	format PlayerId 8. FirstName LastName 'Market (Marketing)'n Date Date9. Sales;
	input PlayerId FirstName $ LastName $ 'Market (Marketing)'n  $ Date Sales;
run;
%end;
%else %do;
data work.import;
run;
%end;
%mend;

%import_date;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2022 20:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833430#M329472</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-14T20:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Failure to import csv data using fileexist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833432#M329474</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377271"&gt;@mmaleta851&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The %let path=C\\; is just a placeholder for the file path I use not my actual file path..&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Does not invalid the concerns about the spaces in the fileexist call for the file name. Have you indeed verified, somewhere, that the string you create matches an actual file name in the operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes it makes sense to create a separate macro variable to hold the value. Especially since it is reused such as your INFILE statement. That way you only have to correct syntax issues, such as the spaces before .CSV in one place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next bit: Is that path relative the SAS system running the code? If the path starts at C:\ then it would be the C:\ of the server running SAS if you are running any server version.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 20:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Failure-to-import-csv-data-using-fileexist/m-p/833432#M329474</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-14T20:27:09Z</dc:date>
    </item>
  </channel>
</rss>

