<?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: use original filename while importing using macro in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576430#M17672</link>
    <description>&lt;P&gt;I am not using .csv for sas file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is converting csv file into sas file.&lt;/P&gt;&lt;P&gt;After converting.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data11.csv becomes data11.sasdata&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jul 2019 01:49:57 GMT</pubDate>
    <dc:creator>april_cz</dc:creator>
    <dc:date>2019-07-25T01:49:57Z</dc:date>
    <item>
      <title>use original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576426#M17670</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; and the imported sas data file name: data11.sasdata .&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:&lt;/P&gt;&lt;P&gt;&lt;STRONG&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;/STRONG&gt;&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;&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 color="#339966"&gt;out=dsn&amp;amp;cnt&lt;/FONT&gt; &lt;FONT color="#339966"&gt;/*this is the part I need 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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 01:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576426#M17670</guid>
      <dc:creator>april_cz</dc:creator>
      <dc:date>2019-07-25T01:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: use original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576428#M17671</link>
      <description>&lt;P&gt;data11.csv is not a valid SAS table name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 01:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576428#M17671</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-07-25T01:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: use original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576430#M17672</link>
      <description>&lt;P&gt;I am not using .csv for sas file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is converting csv file into sas file.&lt;/P&gt;&lt;P&gt;After converting.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data11.csv becomes data11.sasdata&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 01:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576430#M17672</guid>
      <dc:creator>april_cz</dc:creator>
      <dc:date>2019-07-25T01:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: use original filename while importing using macro</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576498#M17675</link>
      <description>&lt;P&gt;If I read the macro code you've posted right then %qsysfunc(dread(&amp;amp;did,&amp;amp;i)) will return the source file name with suffix.&lt;/P&gt;
&lt;P&gt;You just need to parse out the name without suffix. Below code is untested and will only work for source file names without a second dot in the name.&lt;/P&gt;
&lt;PRE class="xis-code"&gt;%let name2=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-2,.);&lt;/PRE&gt;
&lt;P&gt;So you could change your code to something like:&lt;/P&gt;
&lt;PRE class="xis-code"&gt;&lt;FONT color="#339966"&gt;.....out=work.&amp;amp;name2&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;But: This will only work if your external files comply with SAS naming standards.&lt;/P&gt;
&lt;P&gt;Else you will either need something ugly like:&lt;/P&gt;
&lt;PRE&gt;.....out=work."%sysfunc(substrn(&amp;amp;name2,1,32))"n&lt;/PRE&gt;
&lt;P&gt;...or you need to pre-process &amp;amp;name and ensure/convert it to a SAS compliant table name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively add the source file name as label&lt;/P&gt;
&lt;PRE&gt;.....out=dsn&amp;amp;cnt(label="&amp;amp;name2")&lt;/PRE&gt;
&lt;P&gt;....or with suffix included&lt;/P&gt;
&lt;PRE&gt;.....out=dsn&amp;amp;cnt(label="%qsysfunc(dread(&amp;amp;did,&amp;amp;i))")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 08:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/use-original-filename-while-importing-using-macro/m-p/576498#M17675</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-07-25T08:55:51Z</dc:date>
    </item>
  </channel>
</rss>

