<?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: Importing multiple delimited txt files and saving as unique data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503614#M134614</link>
    <description>&lt;P&gt;Hello Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be accomplish by using Macro . Here you can go ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\Directory;

%MACRO IMPORT_TXT(FILENAME=,OUTFILENAME=);
proc import datafile="&amp;amp;path.\&amp;amp;FILENAME..txt" dbms=dlm out=work.&amp;amp;OUTFILENAME replace;
delimiter='$';
run;
%MEND;

/* Calling Macro to import First file  */
%IMPORT_TXT(FILENAME=test1,OUTFILENAME=test1);

/* Calling Macro to import First file  */
%IMPORT_TXT(FILENAME=test2,OUTFILENAME=test2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Just you have to call macro by passing parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;</description>
    <pubDate>Fri, 12 Oct 2018 02:10:34 GMT</pubDate>
    <dc:creator>singhsahab</dc:creator>
    <dc:date>2018-10-12T02:10:34Z</dc:date>
    <item>
      <title>Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503613#M134613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to import multiple TXT files from a local directory that are delimited by the character '$'. The files each have different headers and I want to output them into my work directory as separate data sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc import datafile='C:\Directory\*.txt' dbms=dlm out=work.file_name;
delimiter='$';
run;&lt;/PRE&gt;&lt;P&gt;Is there a command line for the 'out=' portion of the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 01:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503613#M134613</guid>
      <dc:creator>mnguye17</dc:creator>
      <dc:date>2018-10-12T01:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503614#M134614</link>
      <description>&lt;P&gt;Hello Dear,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be accomplish by using Macro . Here you can go ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=C:\Directory;

%MACRO IMPORT_TXT(FILENAME=,OUTFILENAME=);
proc import datafile="&amp;amp;path.\&amp;amp;FILENAME..txt" dbms=dlm out=work.&amp;amp;OUTFILENAME replace;
delimiter='$';
run;
%MEND;

/* Calling Macro to import First file  */
%IMPORT_TXT(FILENAME=test1,OUTFILENAME=test1);

/* Calling Macro to import First file  */
%IMPORT_TXT(FILENAME=test2,OUTFILENAME=test2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Just you have to call macro by passing parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 02:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503614#M134614</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-10-12T02:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503617#M134617</link>
      <description>&lt;P&gt;Here's a fully fledged macro. Point it to the folder and specify the extension it imports all the files. If your file names will not be valid SAS data set names you'll have to modify it to account for that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://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;Several other useful macro examples are here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191225"&gt;@mnguye17&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to import multiple TXT files from a local directory that are delimited by the character '$'. The files each have different headers and I want to output them into my work directory as separate data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc import datafile='C:\Directory\*.txt' dbms=dlm out=work.file_name;
delimiter='$';
run;&lt;/PRE&gt;
&lt;P&gt;Is there a command line for the 'out=' portion of the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 02:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503617#M134617</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-12T02:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503684#M134641</link>
      <description>&lt;P&gt;Thanks, I appreciate the effort!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503684#M134641</guid>
      <dc:creator>mnguye17</dc:creator>
      <dc:date>2018-10-12T12:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503725#M134656</link>
      <description>&lt;P&gt;So, I was able to run the code and it imported all my text files from the directory as individual data sets like I originally wanted. But, I'm having trouble retaining the name of the original text file in the imported data set. It simply renames to Dsn# due to this line of code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;          proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))" out=dsn&amp;amp;cnt &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there a way to retain the name of the original name from the text file in the out=dsn&amp;amp;cnt portion?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 13:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503725#M134656</guid>
      <dc:creator>mnguye17</dc:creator>
      <dc:date>2018-10-12T13:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple delimited txt files and saving as unique data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503737#M134657</link>
      <description>&lt;P&gt;You cannot put it into the dataset as a variable. Not using PROC IMPORT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put you could put it into the dataset label.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))"
 out=dsn&amp;amp;cnt (label="&amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i))")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the names of the files are like XXX.txt then you might be able to parse out the XXX and use that as the name.&amp;nbsp; But then your program will break if the XXX part is not valid as a dataset name.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 14:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-delimited-txt-files-and-saving-as-unique-data/m-p/503737#M134657</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-12T14:15:40Z</dc:date>
    </item>
  </channel>
</rss>

