<?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: Import if exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770470#M244449</link>
    <description>&lt;P&gt;You can't mix Data Steps and Proc Steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could wrap your proc import into a SAS macro defined before the data step and then use call execute() in the data step to call the macro.&lt;/P&gt;
&lt;P&gt;Call Execute() will stack up the macro calls and then execute them once the data step completed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your monthly data should always have the same structure and result in SAS tables with the same variable names AND variable attributes like lengths then I'd strongly recommend that you don't use Proc Import but an explicit INPUT statement.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Sep 2021 08:31:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2021-09-26T08:31:51Z</dc:date>
    <item>
      <title>Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770468#M244447</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to import files into sas if they exists.&lt;/P&gt;
&lt;P&gt;These files that I want to import has name structure&amp;nbsp; RevenueYYYYMMDD.&lt;/P&gt;
&lt;P&gt;It means that I enter dates in a data set and I want to import files with these names.&lt;/P&gt;
&lt;P&gt;What is wrong with my code that I get an error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Source&amp;amp;FileImport. ;
set datestbl;
filename = "/path/Revenue&amp;amp;FileImport..txt";
if fileexist(filename) then do;
 proc import datafile ="/path/Revenue&amp;amp;FileImport..txt"
 out=wanted&amp;amp;FileDate.
 dbms = dlm
 replace
 ;
 delimiter = ';';
 end;
run;     
/*47          proc import datafile ="/path/Revenue&amp;amp;FileImport..txt"*/
/*           _*/
/*           117*/
/**/
/*ERROR 117-185: There was 1 unclosed DO block.*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 07:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770468#M244447</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-26T07:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770470#M244449</link>
      <description>&lt;P&gt;You can't mix Data Steps and Proc Steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could wrap your proc import into a SAS macro defined before the data step and then use call execute() in the data step to call the macro.&lt;/P&gt;
&lt;P&gt;Call Execute() will stack up the macro calls and then execute them once the data step completed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your monthly data should always have the same structure and result in SAS tables with the same variable names AND variable attributes like lengths then I'd strongly recommend that you don't use Proc Import but an explicit INPUT statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 08:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770470#M244449</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-26T08:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770473#M244450</link>
      <description>&lt;P&gt;You can use the same solution as in your earlier thread at&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/proc-delete-data-set-if-exists/m-p/755250" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/proc-delete-data-set-if-exists/m-p/755250&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;modified appropriately to use PROC IMPORT instead of PROC DELETE.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 09:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770473#M244450</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-26T09:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770481#M244453</link>
      <description>&lt;P&gt;May you please let me know if this code will work well?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_one(date);
%if%sysfunc(fileexist(path/revenue&amp;amp;date..csv))
%then%do;
HERE write PROC IMPORT
%end;
%mend;

Data dates_tbl;
input dates $;
cards;
20210603
20210601
20210528
20210514
;
Run;


Data _Null_;
SET dates_tbl;
callexecute('%nrstr(%import_one('!!date!!'))');
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Sep 2021 12:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770481#M244453</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-26T12:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770482#M244454</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;May you please let me know if this code will work well?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can run it yourself and find out if it works.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 12:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770482#M244454</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-26T12:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770483#M244455</link>
      <description>I ask theortically if it will be fine after reading your inputs</description>
      <pubDate>Sun, 26 Sep 2021 12:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770483#M244455</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-26T12:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770484#M244456</link>
      <description>&lt;P&gt;Some things you can find out for yourself.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 12:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770484#M244456</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-26T12:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Import if exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770488#M244458</link>
      <description>&lt;P&gt;I have no SAS now but i will have a look when I have SAS available,cheers&lt;/P&gt;</description>
      <pubDate>Sun, 26 Sep 2021 12:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-if-exists/m-p/770488#M244458</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-26T12:37:18Z</dc:date>
    </item>
  </channel>
</rss>

