<?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 keep original filename while importing using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-original-filename-while-importing-using-macro/m-p/576422#M163158</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import all csv files under a folder using macro. I want to keep the original file name. (for example: original file name: data11.csv&amp;nbsp; importedsas data file name: data11 .&lt;/P&gt;&lt;P&gt;I find following macro program can import the files, my question is how can modify it to retain the original file name rather than generate a new name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro I find on line:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="xis-code"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name; 
   %let cnt=0;          

   %let filrf=mydir;    
   %let rc=%sysfunc(filename(filrf,&amp;amp;dir)); 
   %let did=%sysfunc(dopen(&amp;amp;filrf));
    %if &amp;amp;did ne 0 %then %do;   
   %let memcnt=%sysfunc(dnum(&amp;amp;did));    

    %do i=1 %to &amp;amp;memcnt;              
                       
      %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);                    
                    
      %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
       %if %superq(ext) = %superq(name) %then %do;                         
          %let cnt=%eval(&amp;amp;cnt+1);       
          %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));  
          proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" &lt;FONT size="3" color="#FF0000"&gt;&lt;STRONG&gt;out=dsn&amp;amp;cnt&lt;/STRONG&gt; /*this is name part I want to change*/&lt;/FONT&gt;
           dbms=csv replace;            
          run;          
       %end; 
      %end;  

    %end;
      %end;
  %else %put &amp;amp;dir cannot be open.;
  %let rc=%sysfunc(dclose(&amp;amp;did));      
             
 %mend drive;
 
%drive(c:\temp,csv) 
  &lt;/PRE&gt;</description>
    <pubDate>Thu, 25 Jul 2019 01:27:51 GMT</pubDate>
    <dc:creator>april_cz</dc:creator>
    <dc:date>2019-07-25T01:27:51Z</dc:date>
    <item>
      <title>keep original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-original-filename-while-importing-using-macro/m-p/576422#M163158</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to import all csv files under a folder using macro. I want to keep the original file name. (for example: original file name: data11.csv&amp;nbsp; importedsas data file name: data11 .&lt;/P&gt;&lt;P&gt;I find following macro program can import the files, my question is how can modify it to retain the original file name rather than generate a new name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro I find on line:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="xis-code"&gt;%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name; 
   %let cnt=0;          

   %let filrf=mydir;    
   %let rc=%sysfunc(filename(filrf,&amp;amp;dir)); 
   %let did=%sysfunc(dopen(&amp;amp;filrf));
    %if &amp;amp;did ne 0 %then %do;   
   %let memcnt=%sysfunc(dnum(&amp;amp;did));    

    %do i=1 %to &amp;amp;memcnt;              
                       
      %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);                    
                    
      %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
       %if %superq(ext) = %superq(name) %then %do;                         
          %let cnt=%eval(&amp;amp;cnt+1);       
          %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));  
          proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" &lt;FONT size="3" color="#FF0000"&gt;&lt;STRONG&gt;out=dsn&amp;amp;cnt&lt;/STRONG&gt; /*this is name part I want to change*/&lt;/FONT&gt;
           dbms=csv replace;            
          run;          
       %end; 
      %end;  

    %end;
      %end;
  %else %put &amp;amp;dir cannot be open.;
  %let rc=%sysfunc(dclose(&amp;amp;did));      
             
 %mend drive;
 
%drive(c:\temp,csv) 
  &lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 01:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-original-filename-while-importing-using-macro/m-p/576422#M163158</guid>
      <dc:creator>april_cz</dc:creator>
      <dc:date>2019-07-25T01:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: keep original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-original-filename-while-importing-using-macro/m-p/576497#M163184</link>
      <description>&lt;P&gt;That's a duplicate with answers already here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576426#M17670" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576426#M17670&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 08:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-original-filename-while-importing-using-macro/m-p/576497#M163184</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-07-25T08:29:24Z</dc:date>
    </item>
  </channel>
</rss>

