<?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 files and merging into one database in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76484#M16563</link>
    <description>Hi Bryce, firstly the cards statement simple allows SAS to read in some test data from within the program. As data _null_ does not have your files he created some test data using the cards statment. In your program the word 'cards' would be replaced by the name of your pipe fileref so your values would not be from cards but what is actually returned from the command. I have stuck some comments in in CAPS.&lt;BR /&gt;
&lt;BR /&gt;
It's been a while since I used proc import (as the site I am on does not have access to csvs) but if I recall, it will create SAS code and put that in the log. The SAS code will use the infile/input way of reading in the data. Copy and paste that code into your program to get a good starting point. I may be wrong and maybe it doesnt put the cod ein the log, you'll have to correct me on that one.&lt;BR /&gt;
&lt;BR /&gt;
I wanted to walk through this, I am commenting it so maybe you can direct me in the things I do not understand.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
* create test data(files to be read in next step);&lt;BR /&gt;
data _null_;&lt;BR /&gt;
length command $256; *command will be the location of the files;&lt;BR /&gt;
infile cards truncover; *tells SAS to read through the cards later in the program;&lt;BR /&gt;
input name :$128.; *what it reads in will be called 'name' What does the ':' do? THE DOT IS JUST PART OF THE FORMAT NAME, TELLING SAS THAT IT SHOULD EXPECT THE VALUES TO BE 128 BYTES OF CHARACTER (OR LESS, THATS WHAT THE : TELLS IT)&lt;BR /&gt;
if _n_ eq 1 then do;&lt;BR /&gt;
path = quote(substr(name,1,find(name,'\',-length(name)))); *define the path name;&lt;BR /&gt;
command = 'rmdir /S /Q ".\xUsers\"'; *don't understand this step; THIS IS THE COMMAND TO THE DOS PROMPT/PIPE DEVICE;&lt;BR /&gt;
infile dummy1 pipe filevar=command; *read all of the files located in the command location (or open a pipe to that location);&lt;BR /&gt;
command=catx(' ','mkdir',path); *creates this directory with the location designated in path;&lt;BR /&gt;
put command=;&lt;BR /&gt;
infile dummy1 pipe filevar=command; *pipe again to command location. What exactly does filevar= do?; FILEVAR IS A VARIABLE WHICH HOLD THE NAME OF THE FILE SO YOU CAN TELL IT TO READ DIFFERENT FILES, IT DOSNT HAVE TO BE HARD CODED.&lt;BR /&gt;
rc = sleep(1);&lt;BR /&gt;
end;&lt;BR /&gt;
file dummy filevar=name dsd dlm=',';&lt;BR /&gt;
do _n_ = 1 to 6;&lt;BR /&gt;
put _n_:z5. name;&lt;BR /&gt;
end; SO THIS CARDS STATEMENT IS JUST TEST DATA, YOU WONT USE THAT, YOU WILL USE WHAT YOU GET THROUGH THE PIPE.&lt;BR /&gt;
cards; *read the cards. How do I get ALL the files I need here?;&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05132005.1&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05132005.2&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX0513.DRF&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05142005.1&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05142005.2&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX0514.DRF&lt;BR /&gt;
;;;;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*Read Type .1 (RACE) files;&lt;BR /&gt;
&lt;BR /&gt;
data type1;&lt;BR /&gt;
length command filename fname path $256.;&lt;BR /&gt;
command = 'dir /s /b ".\xUsers"'; *dir has not been defined how does this work?; THIS IS THE COMMAND TO DOS.&lt;BR /&gt;
infile dummy1 pipe filevar=command truncover;&lt;BR /&gt;
input path $256.;&lt;BR /&gt;
if scan(path,-1,'.') eq '1'; *selects only the .1 files;&lt;BR /&gt;
put _infile_; *???;&lt;BR /&gt;
infile dummy2 filevar=path filename=fname end=eof dsd;&lt;BR /&gt;
filename = scan(fname,-2,'.\'); *fname does not exist in this data set at the end?;&lt;BR /&gt;
length prefix $3.;&lt;BR /&gt;
prefix = filename; *assumes prefix is always first 3 characters;&lt;BR /&gt;
date = input (substr(filename,anydigit(filename)),mmddyy10.);&lt;BR /&gt;
do while(not eof);&lt;BR /&gt;
input obs name:$64.; ** Fields for type 1 files?;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In the end I get a data file with the variables you defined; filename, prefix, date, ... I know you wrote above to put in the field types for the data do I need to first declare them in the lenght statement above? It does not seem to be reading any information from the file itself only the file name so far.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
    <pubDate>Mon, 09 Mar 2009 15:51:06 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-09T15:51:06Z</dc:date>
    <item>
      <title>Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76462#M16541</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have given the task of importing many files merging them then combining these into a large database.  Here is the setup.&lt;BR /&gt;
&lt;BR /&gt;
I have 7 files from certain days and certain locations throughout a year in a folder titled with the respective year (2004-2008).  Something like this: C:\Users\mherrin\Documents\Data\2005&lt;BR /&gt;
Each of these folders contains 20,000+ files&lt;BR /&gt;
&lt;BR /&gt;
I would like to import 3 of the 7 files from each day and location and merge them so I have one file per day per location.  Then repeat this process for each day and location for all the files in the folder.&lt;BR /&gt;
&lt;BR /&gt;
The next step will be to combine all of these into one data file for the entire year.  Repeat this process in each folder then combine the yearly data files into a comprehensive database.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I have written the code to import and merge the files but now I think I need to make a macro to repeat this process.&lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated.  THANKS</description>
      <pubDate>Thu, 05 Mar 2009 16:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76462#M16541</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-05T16:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76463#M16542</link>
      <description>The SAS Macro Language Guide has a section on the topic "Generating Repetitive Pieces of Text Using %DO Loops", which discusses using %DO/%END loops within a macro execution.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_91/base_macro_6997.pdf" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_91/base_macro_6997.pdf&lt;/A&gt;</description>
      <pubDate>Thu, 05 Mar 2009 17:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76463#M16542</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-05T17:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76464#M16543</link>
      <description>I am using the pipe command to read all of the file names out of my folder like so:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename indata pipe 'dir C:\Users\mherrin\Documents\trial /b';&lt;BR /&gt;
data file_list;&lt;BR /&gt;
length fname $20;&lt;BR /&gt;
infile indata truncover; /* infile statement for file names */&lt;BR /&gt;
input fname $20.; /* read the file names from the directory */&lt;BR /&gt;
call symput ('fname',fname);&lt;BR /&gt;
call symput ('num_files',_n_); /* store the record number in a macro variable */&lt;BR /&gt;
call symput ('name',substr(fname,1,11));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
But then how do I get my proc import command to read all of those file names?  &lt;BR /&gt;
This is what I have tried.&lt;BR /&gt;
&lt;BR /&gt;
%macro work;&lt;BR /&gt;
PROC IMPORT OUT= &amp;amp;fname &lt;BR /&gt;
            DATAFILE= "C:\Users\mherrin\Documents\trial\&amp;amp;fname" &lt;BR /&gt;
            DBMS=CSV REPLACE;&lt;BR /&gt;
			getnames=no;			&lt;BR /&gt;
	RUN;&lt;BR /&gt;
%mend work;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I am obviously missing the loop part of this process.  I am sure this is something simple that I just cannot find.  If I could get these to read in I think I would be on my way to figuring out the rest.  Thanks!</description>
      <pubDate>Thu, 05 Mar 2009 22:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76464#M16543</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-05T22:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76465#M16544</link>
      <description>I think reading 20,000+ files with PROC IMPORT will be too slow.&lt;BR /&gt;
&lt;BR /&gt;
1) Can the files be read using the same input statements.  Hopefully you don't have 20,000 file with vastly different record layout.&lt;BR /&gt;
&lt;BR /&gt;
2) show directory and file name "structure" in more detail.  You description was too abstract for me, I'm not very bright.&lt;BR /&gt;
&lt;BR /&gt;
3) I didn't get that bit about 3 of 7 or something and how that is determined.  &lt;BR /&gt;
&lt;BR /&gt;
4) This call probably all be done with ONE data step.  But I need to know more details.  The "have" and "need" so to speak.</description>
      <pubDate>Thu, 05 Mar 2009 23:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76465#M16544</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-05T23:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76466#M16545</link>
      <description>Sure I will explain more, anything for some help.&lt;BR /&gt;
&lt;BR /&gt;
In each data folder there are 20,000+ files.  7 from each day and each location, these have different input layouts.  Currently I need to merge only 3 of these 7 daily files.  The paths and filenames are:&lt;BR /&gt;
&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX05132005.1&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX05132005.2&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX0513.DRF&lt;BR /&gt;
&lt;BR /&gt;
for another day it would be like:&lt;BR /&gt;
&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX05142005.1&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX05142005.2&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\APX0514.DRF&lt;BR /&gt;
&lt;BR /&gt;
Where 05 is the month 14 is the day 2005 is the year.&lt;BR /&gt;
And for another location:&lt;BR /&gt;
&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\PEN05142005.1&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\PEN05142005.2&lt;BR /&gt;
C:\Users\mherrin\Documents\trial\PEN0514.DRF&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I need to import each of these sets of three and merge them into a daily file.  &lt;BR /&gt;
&lt;BR /&gt;
The files come without variable names, so I inefficiently named them with a data step using the rename function.  But that part is done.&lt;BR /&gt;
&lt;BR /&gt;
I have written code to input one specific file for all 7 types and the code to merge the 3 desired together.&lt;BR /&gt;
&lt;BR /&gt;
We can focus on just the 3 desired files for now, so it will be more like 10,000 files per year.  We bought a machine that is supposed to be FAST (dell precision T7400).  I think what I need is a macro that will cycle through these files importing them into sas and merging them into a daily file.  These will then be appended into one yearly data set.&lt;BR /&gt;
&lt;BR /&gt;
I hope you can help.  Thanks.</description>
      <pubDate>Fri, 06 Mar 2009 00:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76466#M16545</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T00:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76467#M16546</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Your input datastep from the pipe command will only ever give you the last line it processed, ie the last file. You need to give the macro variables you create some sort of unique identifier for each file. Just an iterative number will do and it might as well be the _n_ of the record being processed.&lt;BR /&gt;
&lt;BR /&gt;
So when you do the call symput write (sorry I cant see the original post but it was something like this):&lt;BR /&gt;
&lt;BR /&gt;
call symput(compress('fname'!!_n_),filename);&lt;BR /&gt;
&lt;BR /&gt;
You will also need to store the total number of files so put a call symput in for that too (it will execute every time but when it's done it will have the value of the last one, you could make this more efficient if you wanted)....&lt;BR /&gt;
&lt;BR /&gt;
call symput('tot_files',_n_);&lt;BR /&gt;
&lt;BR /&gt;
Then you will end up with a macro variable for each file..&lt;BR /&gt;
&lt;BR /&gt;
fname1&lt;BR /&gt;
fname2&lt;BR /&gt;
fname3 etc&lt;BR /&gt;
&lt;BR /&gt;
then create a loop in the macro to run through each fname and import. Something like (I hope you understand double ampersands, if not see documentation)...&lt;BR /&gt;
&lt;BR /&gt;
%do i %to &amp;amp;tot_files;&lt;BR /&gt;
proc import out=&amp;amp;&amp;amp;fname&amp;amp;i datafile='..........&lt;BR /&gt;
..........&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
Hopefully that points you in the right direction. Obviously the %d loop will need to be inside a macro.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: pznew

Message was edited by: pznew</description>
      <pubDate>Fri, 06 Mar 2009 10:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76467#M16546</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T10:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76468#M16547</link>
      <description>I'm still not sure exactly where the similarities are I will assume all file types have the same record structure.  Therefore all type 1 files can be read with one data step.  This example creates data(files) and reads them, into one data set.  &lt;BR /&gt;
&lt;BR /&gt;
Let me know your questions.  All infile and file options are documented. And PIPE example are found in  "Companion" and at support.sas.com&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
* create test data(files to be read in next step);&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   length command $256;&lt;BR /&gt;
   infile cards truncover;&lt;BR /&gt;
   input name :$128.;&lt;BR /&gt;
   if _n_ eq 1 then do;&lt;BR /&gt;
      path = quote(substr(name,1,find(name,'\',-length(name))));&lt;BR /&gt;
      command = 'rmdir /S /Q ".\xUsers\"';&lt;BR /&gt;
      infile dummy1 pipe filevar=command;&lt;BR /&gt;
      command = catx(' ','mkdir',path); &lt;BR /&gt;
      put command=;&lt;BR /&gt;
      infile dummy1 pipe filevar=command;&lt;BR /&gt;
      rc = sleep(1); *small delay;&lt;BR /&gt;
      end;&lt;BR /&gt;
   file dummy filevar=name dsd dlm=',';&lt;BR /&gt;
   do _n_ = 1 to 10;&lt;BR /&gt;
      put _n_:z5. name;&lt;BR /&gt;
      end;&lt;BR /&gt;
   cards;&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05132005.1&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05132005.2&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX0513.DRF&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05142005.1&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX05142005.2&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\APX0514.DRF&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\PEN05142005.1&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\PEN05142005.2&lt;BR /&gt;
.\xUsers\mherrin\Documents\trial\PEN0514.DRF&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
*** Read all the type .1 records;&lt;BR /&gt;
data Type1;&lt;BR /&gt;
   length command filename fname path $256.;&lt;BR /&gt;
   command = 'dir /s /b ".\xUsers"';&lt;BR /&gt;
   infile dummy1 pipe filevar=command truncover;&lt;BR /&gt;
   input path $256.;&lt;BR /&gt;
   if scan(path,-1,'.') eq '1';&lt;BR /&gt;
   put _infile_;&lt;BR /&gt;
   infile dummy2 filevar=path filename=fname end=eof dsd;&lt;BR /&gt;
   filename = scan(fname,-2,'.\');&lt;BR /&gt;
   length prefix $3;&lt;BR /&gt;
   prefix   = filename; * assumes prefix is always first 3 chars;&lt;BR /&gt;
   date     = input(substr(filename,anydigit(filename)),mmddyy10.);&lt;BR /&gt;
   do while(not eof);&lt;BR /&gt;
      input obs name:$64.; ** Fields for type 1 files?;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   format date date9.;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 06 Mar 2009 12:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76468#M16547</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-06T12:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76469#M16548</link>
      <description>Thanks for the help.&lt;BR /&gt;
&lt;BR /&gt;
I am having some success with the do loop in a macro I think but I get two errors;&lt;BR /&gt;
&lt;BR /&gt;
1) ERROR: Library name is not assigned.&lt;BR /&gt;
2)ERROR: Libname 'APX05132005' exceeds 8 characters.&lt;BR /&gt;
&lt;BR /&gt;
I think this is due to the fact that &amp;amp;&amp;amp;fname&amp;amp;i converts to APX05132005.1 and sas thinks that the first part is the libname.&lt;BR /&gt;
&lt;BR /&gt;
I would like to use an if statement as well in the macro.  This is what I am thinking of doing.  I commented it so you would have a better chance of understanding what I am "trying" to do.  Please point out any mistakes.  I appreciate all the help.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename indata pipe 'dir C:\Users\mherrin\Documents\trial /b';&lt;BR /&gt;
data file_list;&lt;BR /&gt;
length fname $20;&lt;BR /&gt;
infile indata truncover; /* infile statement for file names */&lt;BR /&gt;
input fname $20.; /* read the file names from the directory */&lt;BR /&gt;
call symput (compress('fname'!!_n_),fname);&lt;BR /&gt;
call symput ('num_files',_n_); /* store the record number in a macro variable */&lt;BR /&gt;
call symput (compress('name'!!_n_),substr(fname,1,11));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put _global_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro work;&lt;BR /&gt;
%do i=1 %to &amp;amp;num_files;&lt;BR /&gt;
PROC IMPORT OUT= '&amp;amp;&amp;amp;fname&amp;amp;i'&lt;BR /&gt;
            DATAFILE= "C:\Users\mherrin\Documents\trial\&amp;amp;&amp;amp;fname&amp;amp;i" &lt;BR /&gt;
            DBMS=CSV REPLACE;&lt;BR /&gt;
			getnames=no;			&lt;BR /&gt;
	RUN;&lt;BR /&gt;
%if scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.') eq '1' %then %do; * for the .1 files;&lt;BR /&gt;
	data &amp;amp;&amp;amp;fname&amp;amp;i;&lt;BR /&gt;
		set &amp;amp;&amp;amp;fname&amp;amp;i(rename=(var1=... var99=);&lt;BR /&gt;
	run;&lt;BR /&gt;
	data &amp;amp;&amp;amp;name&amp;amp;i;  *This will be the comprehensive daily file;&lt;BR /&gt;
		set &amp;amp;fname&amp;amp;i;  *(i.e. APX05132005 for the first set of files);&lt;BR /&gt;
	run;;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.') eq '2' %then %do; /*for the .2 files*/&lt;BR /&gt;
	data &amp;amp;&amp;amp;fname&amp;amp;i;&lt;BR /&gt;
		set &amp;amp;&amp;amp;fname&amp;amp;i(rename=(var1=... var99=); /*different variable names*/&lt;BR /&gt;
	run;&lt;BR /&gt;
	data &amp;amp;&amp;amp;name&amp;amp;i;  /*Merge the first two files together to begin the comprehensive file*/ &lt;BR /&gt;
		merge &amp;amp;&amp;amp;name&amp;amp;i &amp;amp;&amp;amp;fname&amp;amp;i;&lt;BR /&gt;
		by raceNum;&lt;BR /&gt;
		if PostPosition=99 then delete;  /*can you do this in the same data step?*/&lt;BR /&gt;
	run;&lt;BR /&gt;
	data &amp;amp;&amp;amp;name&amp;amp;i;&lt;BR /&gt;
		set &amp;amp;&amp;amp;name&amp;amp;i(drop=PostPos PostPosition); /*these must be removed for merge later*/&lt;BR /&gt;
	run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%else %if scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.') eq 'D' %then %do;  /*for the .drf files*/&lt;BR /&gt;
	data &amp;amp;&amp;amp;fname&amp;amp;i;&lt;BR /&gt;
		set &amp;amp;&amp;amp;fname&amp;amp;i(rename=(var1=... var1435=); /*different variable names*/&lt;BR /&gt;
	run;&lt;BR /&gt;
	data &amp;amp;&amp;amp;name&amp;amp;i-;  /*can you do an i-1 type macro? Because the way I used name  &amp;amp;&amp;amp;name&amp;amp;i would be APX0513.DRF in this case*/&lt;BR /&gt;
		merge &amp;amp;&amp;amp;name&amp;amp;i &amp;amp;&amp;amp;fname&amp;amp;i;&lt;BR /&gt;
		by raceNum ProgNum; /*I may have to sort these sets first*/&lt;BR /&gt;
	run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend work;&lt;BR /&gt;
&lt;BR /&gt;
%work;</description>
      <pubDate>Fri, 06 Mar 2009 17:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76469#M16548</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T17:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76470#M16549</link>
      <description>It will certainly think the . is a seperator between the libref and the dataset name. You should change the dot to something else. Use the translate function to do that. Also you need to surround the macro variable with double quites " and not single ' or it will not resolve.&lt;BR /&gt;
&lt;BR /&gt;
Do somethig like this....&lt;BR /&gt;
&lt;BR /&gt;
out="%sysfuc(translate(&amp;amp;&amp;amp;fname&amp;amp;i, _ , . ))";&lt;BR /&gt;
&lt;BR /&gt;
the sysfunc tells the macro language to use the sas function (remember the macro language and sas language are different things). And because we are not dealing with quoted strings in macro but just characters we do not put quotes round the characters on the translate function that we are translating to and from. ie to _ from .&lt;BR /&gt;
&lt;BR /&gt;
Hoipe that helps in some way.</description>
      <pubDate>Fri, 06 Mar 2009 17:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76470#M16549</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T17:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76471#M16550</link>
      <description>Thanks that was a great help.  One funny thing is happening though.  When I run the code the APX05132005_1 sas data file is not correct.  It contains a list of path names.&lt;BR /&gt;
&lt;BR /&gt;
I tried running this with if statements as well but I received an error reading the following:&lt;BR /&gt;
&lt;BR /&gt;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand&lt;BR /&gt;
       is required. The condition was: scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.') eq '1'&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I feel like we are getting closer.  Thank you for helping.</description>
      <pubDate>Fri, 06 Mar 2009 19:21:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76471#M16550</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T19:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76472#M16551</link>
      <description>Ok both of those errors are fixed.&lt;BR /&gt;
&lt;BR /&gt;
Now I just cant read in the .drf files.&lt;BR /&gt;
&lt;BR /&gt;
%if %scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.')='d' %then %do;&lt;BR /&gt;
&lt;BR /&gt;
Is not working.  Thanks

Message was edited by: Bryce</description>
      <pubDate>Fri, 06 Mar 2009 19:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76472#M16551</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T19:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76473#M16552</link>
      <description>I think I have it running now.  Thanks, you all have been a great help.&lt;BR /&gt;
&lt;BR /&gt;
One more question for now:&lt;BR /&gt;
Is there anyway to prevent the window full popup from occuring.  maybe set it to a clear all everytime?&lt;BR /&gt;
&lt;BR /&gt;
Or should I add a clear window function inside the loop?&lt;BR /&gt;
&lt;BR /&gt;
I think it will take 8 hours to import.  :S  I would "prefer" not to sit here clicking the clear button.  I closed the log window now the message just sais "window full" not "log window full"  &lt;BR /&gt;
&lt;BR /&gt;
I would greatly appreciate it if anyone could answer tonight so I could get all this data imported over the weekend!</description>
      <pubDate>Fri, 06 Mar 2009 23:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76473#M16552</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-06T23:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76474#M16553</link>
      <description>Run it in batch.  Right click filename from winders explorer and select "Batch Submit with SAS 9.1"  Good luck with 20,000 proc imports and all those other steps, I don't think it will ever finish.</description>
      <pubDate>Fri, 06 Mar 2009 23:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76474#M16553</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-06T23:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76475#M16554</link>
      <description>Yeah, your right.  It has been running over the weekend and it is only the the H's&lt;BR /&gt;
&lt;BR /&gt;
what can I do differently? maybe I could import and combine all the same files then change the variable names instead of renaming them in each iteration?  Or should I stay away from proc import all together?&lt;BR /&gt;
&lt;BR /&gt;
Originally it was running faster about 8 seconds per loop so it should have taken 8 hours.  It is running much slower now 15 seconds per loop.  why is this?&lt;BR /&gt;
&lt;BR /&gt;
Let me know if there is a more efficient way of doing this.  Thank you!</description>
      <pubDate>Sun, 08 Mar 2009 16:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76475#M16554</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-08T16:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76476#M16555</link>
      <description>Ensure that you are current on SAS HOTFIX maintenance, as a general rule.  Also, it may help with SAS WORK processing, if you can relocate your WORK allocation to another physical drive.  There are technical papers on the SAS support website  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  to address the SAS Windows performance topic - here is one for consideration (maybe too much detail, but useful info about SAS and I/O such as WORK):&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts684/ts684.html" target="_blank"&gt;http://support.sas.com/techsup/technote/ts684/ts684.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 08 Mar 2009 18:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76476#M16555</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-08T18:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76477#M16556</link>
      <description>&amp;gt; Yeah, your right.  It has been running over the&lt;BR /&gt;
&amp;gt; weekend and it is only the the H's&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; what can I do differently? maybe I could import and&lt;BR /&gt;
&amp;gt; combine all the same files then change the variable&lt;BR /&gt;
&amp;gt; names instead of renaming them in each iteration?  Or&lt;BR /&gt;
&amp;gt; should I stay away from proc import all together?&lt;BR /&gt;
Yes, forget PROC IMPORT, you mentioned the data had no field names row so you are better off writing your own data step to read the data.  Plus you have many file that are similarly structured.&lt;BR /&gt;
&lt;BR /&gt;
I would just write a data step to read all the files of a particular type.  I gave you a example but it may not have been adequate.  You did not provide enough details about the fields to do any more than demonstrate one method of read multiple files.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Originally it was running faster about 8 seconds per&lt;BR /&gt;
&amp;gt; loop so it should have taken 8 hours.  It is running&lt;BR /&gt;
&amp;gt; much slower now 15 seconds per loop.  why is this?&lt;BR /&gt;
&lt;BR /&gt;
It is hard to guess as but leaky memory seems reasonable.  Or maybe your PC just got tired. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Let me know if there is a more efficient way of doing&lt;BR /&gt;
&amp;gt; this.  Thank you!&lt;BR /&gt;
data step....  details to be determined.</description>
      <pubDate>Mon, 09 Mar 2009 14:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76477#M16556</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-09T14:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76478#M16557</link>
      <description>I looked over your example but I did not follow it as well so I tried to stick with the import code.  I will work on that version now.  I do not know how to make the 'cards' option work for the number of files I have.  maybe if i run it through a macro and put the &amp;amp;&amp;amp;filename&amp;amp;i at the end of the path.&lt;BR /&gt;
&lt;BR /&gt;
If you want an idea of exactly what I am trying to do my code is posted below.  It preforms the task but not quickly enough.&lt;BR /&gt;
&lt;BR /&gt;
You can see that I am making one file per day per location.  Would it be more efficient if I began making a yearly data set and delete each daily file after I append it to the end of the yearly data set?  That way sas would not have as many data files in the _2005_ library.  &lt;BR /&gt;
&lt;BR /&gt;
I will try to work my way through your code now.  Thanks!&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;
&lt;BR /&gt;
libname _2005_ "C:\Users\mherrin\Documents\Horse_Racing\daily2005";&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
filename indata pipe 'dir C:\Users\mherrin\Documents\Horse_Racing\2005 /b';&lt;BR /&gt;
data file_list;&lt;BR /&gt;
length fname $20;&lt;BR /&gt;
infile indata truncover; /* infile statement for file names */&lt;BR /&gt;
input fname $20.; /* read the file names from the directory */&lt;BR /&gt;
call symput (compress('fname'!!_n_),fname);&lt;BR /&gt;
call symput ('num_files',_n_); /* store the record number in a macro variable */&lt;BR /&gt;
call symput (compress('name'!!_n_),substr(fname,1,11));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%put _global_;&lt;BR /&gt;
&lt;BR /&gt;
%macro import;&lt;BR /&gt;
%do i=1 %to &amp;amp;num_files;&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
	%if %scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.')=1 %then %do;	&lt;BR /&gt;
		PROC IMPORT OUT= %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))&lt;BR /&gt;
            DATAFILE= "C:\Users\mherrin\Documents\Horse_Racing\2005\&amp;amp;&amp;amp;fname&amp;amp;i" &lt;BR /&gt;
            DBMS=CSV REPLACE;&lt;BR /&gt;
			getnames=no;			&lt;BR /&gt;
		RUN;&lt;BR /&gt;
		data %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			set %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))(rename=(var1=Track var2=Date var3=RaceNum var4=DayFlag var5=Dist &lt;BR /&gt;
			var6=DistUnit var7=DistFlag var8=Surf1 var9=Surf2  &lt;BR /&gt;
			var11=AllWeather var12=Chute var13=BrisType var14=EQBType var15=Grade&lt;BR /&gt;
			var16=ASRest var17=RRest var18=StateFlag var19=Class var20=Breed &lt;BR /&gt;
			var21=Country var22=Purse var23=TotValue &lt;BR /&gt;
			var28=MaxClmgPrice var30-var34=RC1-RC5 &lt;BR /&gt;
			var37=FieldSize var38=TrackCond var39-var43=Frac1-Frac5 var44=FinalTime&lt;BR /&gt;
			var45-var49=FracDist1-FracDist5 &lt;BR /&gt;
			var50=OffTime var51=StartCallDist var52-var54=CallDist1-CallDist3 var55=RaceName &lt;BR /&gt;
			var56=StartDesc var57=RailDist var58= OffTurf var59=OTDistChange &lt;BR /&gt;
		 	var63=Weather var64=RaceTemp var65=WPSPool)&lt;BR /&gt;
			drop=var10 var24-var27 var29 var35 var36 var60-var62 var66-var99);&lt;BR /&gt;
		run;&lt;BR /&gt;
		data %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
			merge %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)) %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,7);&lt;BR /&gt;
			by RaceNum;&lt;BR /&gt;
		run;&lt;BR /&gt;
	%end;&lt;BR /&gt;
	%if %scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.')=2 %then %do;	&lt;BR /&gt;
		PROC IMPORT OUT= %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))&lt;BR /&gt;
            DATAFILE= "C:\Users\mherrin\Documents\Horse_Racing\2005\&amp;amp;&amp;amp;fname&amp;amp;i" &lt;BR /&gt;
            DBMS=CSV REPLACE;&lt;BR /&gt;
			getnames=no;			&lt;BR /&gt;
		RUN;&lt;BR /&gt;
		data %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			set %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))(rename=(var1=Track var2=Date var3=RaceNum var4=DayFlag var5=HorseName&lt;BR /&gt;
			var6=ForeignBred var7=StateBred var8=PostPosition var9=ProgNum&lt;BR /&gt;
			var10=YoB var11=Breed var12=CoupledFlag var13=AbbJName&lt;BR /&gt;
			var14=JLast var15=JFirst var16=JMiddle&lt;BR /&gt;
			Var18=AbbTName var19=TLast var20=TFirst var21=TMiddle&lt;BR /&gt;
			var22=TripComment var24=OName var25=OFirst var26=OMiddle&lt;BR /&gt;
			var27=ClmgPrice var28=MedCode var29=EquipCode Var30=Earnings&lt;BR /&gt;
			var31=Odds var32=NonBetFlag var33=FavFlag var36=DQFlag&lt;BR /&gt;
			var37=DQPlacing var38=Weight var39=CorWeight var40=OWAmount&lt;BR /&gt;
			var41=Claimed var42=ClmAbbTrn var43=ClmTrnLast var44=ClmTrnFirst&lt;BR /&gt;
			var45=ClmTrnMiddle var47=ClmAbbOwn var48=ClmOwnLast&lt;BR /&gt;
			var49=ClmOwnFirst var50=ClmOwnMiddle var51=WinPO var52=PlacePO&lt;BR /&gt;
			var53=ShowPO var55=StPos var56-var58=CallPos1-CallPos3&lt;BR /&gt;
			var59=StretchPos var60=FinishPos Var61=OfficialPos&lt;BR /&gt;
			var62=StLengthsAhd var63-var65=CallLengthsAhd1-CallLengthsAhd3&lt;BR /&gt;
			var66=StretchLengthsAhd var67=FinishLengthsAhd var68=StLengthsBhd&lt;BR /&gt;
			var69-var71=CallLengthsBhd1-CallLengthsbhd3 var72=StrechLengthsBhd&lt;BR /&gt;
			var73=FinishLengthsBhd var74=StCallMgn var75-var77=CallMgn1-CallMgn3&lt;BR /&gt;
			var78=StretchMgn var79=FinishMgn var80=DeadHeatFlag)&lt;BR /&gt;
			drop=var17 var23 var34 var35 var46 var54 var81-var99);&lt;BR /&gt;
		run;&lt;BR /&gt;
		data %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			set %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			if PostPosition=99 then delete;&lt;BR /&gt;
		run;&lt;BR /&gt;
		data %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
			set %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11)(drop=PostPosition PostPos);&lt;BR /&gt;
		run;&lt;BR /&gt;
		proc sort data=%substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
			by racenum prognum;&lt;BR /&gt;
		run;&lt;BR /&gt;
		proc sort data=%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			by racenum prognum;&lt;BR /&gt;
		run;&lt;BR /&gt;
		data %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
		merge %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11) %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
			by racenum prognum;&lt;BR /&gt;
		run;&lt;BR /&gt;
		data _2005_.%substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
			set %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,11);&lt;BR /&gt;
			if postposition=. then delete;&lt;BR /&gt;
		run;&lt;BR /&gt;
		PROC DATASETS LIB=WORK MEMTYPE=DATA&lt;BR /&gt;
    		kill;&lt;BR /&gt;
		RUN;&lt;BR /&gt;
&lt;BR /&gt;
		&lt;BR /&gt;
	%end;&lt;BR /&gt;
	%if %scan(&amp;amp;&amp;amp;fname&amp;amp;i,-1,'.')=DRF %then %do;	&lt;BR /&gt;
		PROC IMPORT OUT= %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))&lt;BR /&gt;
            DATAFILE= "C:\Users\mherrin\Documents\Horse_Racing\2005\&amp;amp;&amp;amp;fname&amp;amp;i" &lt;BR /&gt;
            DBMS=CSV REPLACE;&lt;BR /&gt;
			getnames=no;			&lt;BR /&gt;
		RUN;&lt;BR /&gt;
		data %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
	set %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.))(rename=(var1=Track var2=Date var3=RaceNum var4=PostPos var5=Entry&lt;BR /&gt;
var6=Dist var7=Surface var9=RaceType var10=ASRest &lt;BR /&gt;
var11=RaceClass var12=Purse var13=ClmgPrice var14=ClmgPriceHorse var15=TrackRecord&lt;BR /&gt;
var16=RaceCond var17=LasixList var18=ButeList var19=CoupledList var20=MutuelList&lt;BR /&gt;
var21=SimHT var22=SimHTRaceNum var23=BreedType var24=NasalStpChng var25=AllWeather&lt;BR /&gt;
var28=Trn var29=TrnStarts var30=TrnWins var31=TrnPlaces var32=TrnShows&lt;BR /&gt;
var33=Jockey var34=AppWgtAllow var35=JStarts var36=JWins var37=Jplaces var38=JShows&lt;BR /&gt;
var39=Owner var40=OSilks var41=MainTrackOnly var43=ProgNum var44=MornLine&lt;BR /&gt;
var45=HorseName var46=Yob var47=FoalMonth var49=Sex Var50=HColor&lt;BR /&gt;
var51=Weight var52=Sire var53=SSire var54=Dam var55=DSire&lt;BR /&gt;
var56=Breeder var57=StCountryBred var58=PostPosition&lt;BR /&gt;
var62=NewMeds var63=OldMeds var64=EquipChng &lt;BR /&gt;
var65=TdyDistStarts var66=TdyDistWins var67=TdyDistPlaces var68=TdyDistShows var69=TdyDistEarnings &lt;BR /&gt;
var70=TdyTrackStarts var71=TdyTrackWins var72=TdyTrackPlaces var73=TdyTrackShows var74=TdyTrackEarnings&lt;BR /&gt;
var75=TurfStarts var76=TurfWins var77=TurfPlaces var78=TurfShows var79=TurfEarnings &lt;BR /&gt;
var80=WetStarts var81=WetWins var82=WetPlaces var83=WetShows var84=WetEarnings &lt;BR /&gt;
var85=CurYear var86=CurYearStarts var87=CurYearWins var88=CurYearPlaces var89=CurYearShows var90=CurYearEarnings &lt;BR /&gt;
var91=PrevYear var92=PrevYearStarts var93=PrevYearWins var94=PrevYearPlaces var95=PrevYearShows var96=PrevYearEarnings &lt;BR /&gt;
var97=LifeStarts var98=LifeWins var99=LifePlaces var100=LifeShows var101=LifeEarnings&lt;BR /&gt;
&lt;BR /&gt;
var102-var113=WODate1-WODate12&lt;BR /&gt;
var114-var125=WOTime1-WOTime12&lt;BR /&gt;
var126-var137=WOTrack1-WOTrack12&lt;BR /&gt;
var138-var149=WODist1-WODist12&lt;BR /&gt;
var150-var161=WOTrackCond1-WOTrackCond12&lt;BR /&gt;
var162-var173=WODescript1-WODescript12&lt;BR /&gt;
var174-var185=MITrackIndicator1-MITrackIndicator12&lt;BR /&gt;
var186-var197=NumWorksDD1-NumWorksDD12&lt;BR /&gt;
var198-var209=RankDD1-RankDD12&lt;BR /&gt;
&lt;BR /&gt;
var210=RunStyle var211=QuirinSpdPts var214=f2BrisPacePar var215=f4BrisPacePar var216=f6BrisPacePar&lt;BR /&gt;
var217=BrisSpeedParClass var218=BrisLatePacePar var224=DaysSinceLR var225-var230=DRFRaceCond1-DRFRaceCond6&lt;BR /&gt;
var231=AWSLifeStarts var232=AWSLifeWins var233=AWSLifePlaces var234=AWSLifeShows var235=AWSLifeEarnings&lt;BR /&gt;
var236=AWSBestBrisSpeed var238=LowClmgPrice var239=StateBredFlag&lt;BR /&gt;
var240-var248=WagerType1-WagerType9&lt;BR /&gt;
var251=BrisPowerRtng &lt;BR /&gt;
&lt;BR /&gt;
var256-var265=RaceDate1-RaceDate10&lt;BR /&gt;
var266-var274=DaysSinceLR1-DaysSinceLR9&lt;BR /&gt;
var276-var285=Track1-Track10&lt;BR /&gt;
Var286-var295=BrisTrack1-BrisTrack10&lt;BR /&gt;
Var296-var305=RaceNum1-RaceNum10&lt;BR /&gt;
var306-var315=TrackCond1-TrackCond10&lt;BR /&gt;
var316-var325=Dist1-Dist10&lt;BR /&gt;
var326-var335=Surf1-Surf10&lt;BR /&gt;
var336-var345=SpecChute1-SpecChute10&lt;BR /&gt;
Var346-var355=NumEntrants1-NumEntrants10&lt;BR /&gt;
var356-var365=PostPosition1-PostPosition10&lt;BR /&gt;
var366-var375=Equip1-Equip10&lt;BR /&gt;
Var386-var395=Med1-Med10&lt;BR /&gt;
Var396-var405=TripComment1-TripComment10&lt;BR /&gt;
var406-var415=WinName1-WinName10&lt;BR /&gt;
var416-var425=SecndName1-SecndName10&lt;BR /&gt;
var426-var435=ThrdName1-ThrdName10&lt;BR /&gt;
var436-var445=WinWgt1-WinWgt10&lt;BR /&gt;
var446-var455=SecndWgt1-SecndWgt10&lt;BR /&gt;
var456-var465=ThrdWgt1-ThrdWgt10&lt;BR /&gt;
var466-var475=WinMgn1-WinMgn10&lt;BR /&gt;
var476-var485=SecndMgn1-SecndMgn10&lt;BR /&gt;
var486-var495=ThrdMgn1-ThrdMgn10&lt;BR /&gt;
var496-var505=Comment1-Comment10&lt;BR /&gt;
var506-var515=Wgt1-Wgt10&lt;BR /&gt;
var516-var525=Odds1-Odds10&lt;BR /&gt;
var526-var535=Entry1-Entry10&lt;BR /&gt;
var536-var545=RaceClass1-RaceClass10&lt;BR /&gt;
var546-var555=ClmgPrice1-ClmgPrice10&lt;BR /&gt;
var556-var565=Purse1-Purse10&lt;BR /&gt;
var566-var575=StartCallPos1-StartCallPos10&lt;BR /&gt;
var576-var585=FrstCallPos1-FrstCallPos10&lt;BR /&gt;
var586-var595=SecndCallPos1-SecndCallPos10&lt;BR /&gt;
var596-var605=GateCallPos1-GateCallPos10&lt;BR /&gt;
var606-var615=StretchPos1-StretchPos10&lt;BR /&gt;
var616-var625=FinishPos1-FinishPos10&lt;BR /&gt;
var626-var635=MoneyPos1-MoneyPos10&lt;BR /&gt;
var636-var645=StartCallLgnbtnLead1-StartCallLgnbtnLead10&lt;BR /&gt;
var646-var655=StartCallLgnBtn1-StartCallLgnBtn10&lt;BR /&gt;
var656-var665=FrstCallLgnbtnLead1-FrstCallLgnbtnLead10&lt;BR /&gt;
var666-var675=FrstCallLgnbtn1-FrstCallLgnbtn10&lt;BR /&gt;
var676-var685=SecndCallLgnbtnLead1-SecndCallLgnbtnLead10&lt;BR /&gt;
var686-var695=SecndCallLgnbtn1-SecndCallLgnbtn10&lt;BR /&gt;
var696-var705=Shape1stCall1-Shape1stCall10&lt;BR /&gt;
var716-var725=StretchLgnBtnLead1-StretchLgnBtnLead10&lt;BR /&gt;
var726-var735=StretchLgnBtn1-StretchLgnBtn10&lt;BR /&gt;
var736-var745=FinishLgnBtnLead1-FinishLgnBtnLead10&lt;BR /&gt;
var746-var755=FinishLgnBtn1-FinishLgnBtn10&lt;BR /&gt;
var756-var765=RaceShape2ndCall1-RaceShape2ndCall10&lt;BR /&gt;
var766-var775=f2Pace1-f2Pace10&lt;BR /&gt;
var776-var785=f4Pace1-f4Pace10&lt;BR /&gt;
var786-var795=f6Pace1-f6Pace10&lt;BR /&gt;
var796-var805=f8Pace1-f8Pace10&lt;BR /&gt;
var806-var815=f10Pace1-f10Pace10&lt;BR /&gt;
var816-var825=LatePace1-LatePace10&lt;BR /&gt;
&lt;BR /&gt;
var846-var855=BrisSpeedRating1-BrisSpeedRating10&lt;BR /&gt;
var856-var865=DRFSpeedRating1-DRFSpeedRating10&lt;BR /&gt;
var866-var875=DRFTrackWgt1-DRFTrackWgt10&lt;BR /&gt;
var876-var885=f2Frac1-f2Frac10&lt;BR /&gt;
var886-var895=f3Frac1-f3Frac10&lt;BR /&gt;
var896-var905=f4Frac1-f4Frac10&lt;BR /&gt;
var906-var915=f5Frac1-f5Frac10&lt;BR /&gt;
var916-var925=f6Frac1-f6Frac10&lt;BR /&gt;
var926-var935=f7Frac1-f7Frac10&lt;BR /&gt;
var936-var945=f8Frac1-f8Frac10&lt;BR /&gt;
var946-var955=f10Frac1-f10Frac10&lt;BR /&gt;
var956-var965=f12Frac1-f12Frac10&lt;BR /&gt;
var966-var975=f14Frac1-f14Frac10&lt;BR /&gt;
var976-var985=f16Frac1-f16Frac10&lt;BR /&gt;
var986-var995=Num1Frac1-Num1Frac10&lt;BR /&gt;
var996-var1005=Num2Frac1-Num2Frac10&lt;BR /&gt;
var1006-var1015=Num3Frac1-Num3Frac10&lt;BR /&gt;
var1036-var1045=FinalTime1-FinalTime10&lt;BR /&gt;
var1046-var1055=Claimed1-Claimed10&lt;BR /&gt;
var1056-var1065=Trn1-Trn10&lt;BR /&gt;
var1066-var1075=Jock1-Jock10&lt;BR /&gt;
var1076-var1085=AppWgtAllow1-AppwgtAllow10&lt;BR /&gt;
var1086-var1095=RaceType1-RaceType10&lt;BR /&gt;
var1096-var1105=ASRest1-ASRest10&lt;BR /&gt;
var1106-var1115=StateBred1-StateBred10&lt;BR /&gt;
var1116-var1125=QualFlag1-QualFlag10&lt;BR /&gt;
var1126-var1135=Favorite1-Favorite10&lt;BR /&gt;
var1136-var1145=FBandage1-FBandage10&lt;BR /&gt;
&lt;BR /&gt;
var1147=CurYearTrnStarts var1148=CurYearTrnWins var1149=CurYearTrnPlaces var1150=CurYearTrnShows&lt;BR /&gt;
var1151=CurYearTrnROI var1152=PrevYearTrnStarts var1153=PrevYearTrnWins var1154=PrevYearTrnPlaces&lt;BR /&gt;
var1155=PrevYearTrnShows var1156=PrevYearTrnROI var1157=CurYearJStarts var1158=CurYearJWins&lt;BR /&gt;
var1159=CurYearJPlaces var1160=CurYearJShows var1161=CurYearJROI var1162=PrvYearJStarts &lt;BR /&gt;
var1163=PrevYearJWins var1164=PrevYearJPlaces var1165=PrevYearJShows var1166=PrevYearJROI&lt;BR /&gt;
&lt;BR /&gt;
var1167-var1176=BrisSpeedParClass1-BrisSpeedParClass10&lt;BR /&gt;
&lt;BR /&gt;
var1177=CurrSireStudFee&lt;BR /&gt;
var1178=BestSpFast&lt;BR /&gt;
var1179=BestSPTurf&lt;BR /&gt;
var1180=BestSpOffTrack&lt;BR /&gt;
var1181=BestSpDist&lt;BR /&gt;
var1182-var1191=BarShoe1-BarShoe10&lt;BR /&gt;
var1192-var1201=CompLine1-CompLine10&lt;BR /&gt;
var1202-var1211=LowClmgPrice1-LowClmgPrice10&lt;BR /&gt;
var1212-var1221=HighClmgPrice1-HighClmgPrice10&lt;BR /&gt;
var1222=AuctionPrice&lt;BR /&gt;
var1223=WhereWhenAuction&lt;BR /&gt;
var1254-var1263=Nasaloff1-Nasaloff10&lt;BR /&gt;
var1264=DirtPedRtng var1265=MudPedRtng var1266=TurfPedRtng var1267=DistPedRtng var1328=LifeBestSpeed&lt;BR /&gt;
var1329=FrstRecYrBestSpeed var1330=SecndRecYrBestSpeed var1331=TodayTrackBestSpeed var1332=FDNumStarts var1333=FDNumWins&lt;BR /&gt;
var1334=FDNumPlaces var1335=FDNumShows var1336=FDNumEarnings var1337=KeyStatNum1 var1338=StartsNum1&lt;BR /&gt;
var1339=WinPercNum1 var1340=ITMPercNum1 var1341=twodolROINum1 var1342=KeyStatNum2 var1343=StartsNum2 var1344=WinPercNum2&lt;BR /&gt;
var1345=ITMPercNum2 var1346=twodolROINum2 var1347=KeyStatNum3 var1348=StartsNum3 var1349=WinPercNum3&lt;BR /&gt;
var1350=ITMPercNum3 var1351=twodolROINum3 var1352=KeyStatNum4 var1353=StartsNum4 var1354=WinPercNum4&lt;BR /&gt;
var1355=ITMPercNum4 var1356=twodolROINum4 var1357=KeyStatNum5 var1358=StartsNum5 var1359=WinPercNum5&lt;BR /&gt;
var1360=ITMPercNum5 var1361=twodolROINum5 var1362=KeyStatNum6 var1363=StartsNum6 var1364=WinPercNum6&lt;BR /&gt;
var1365=ITMPercNum6 var1366=twodolROINum6 var1367=JDistJonTurfLabel var1368=JDistJonTurfstarts&lt;BR /&gt;
var1369=JDistJonTurfWins var1370=JDistJonTurfPlaces var1371=JDistJonTurfShows var1372=JDistJonTurfROI&lt;BR /&gt;
var1373=JDistJonTurfEarnings var1374=PostTimesRegion var1383-var1392=ExtStartComment1-ExtStartComment10&lt;BR /&gt;
var1393-var1402=SealedTrack1-SealedTrack10 var1403-var1412=PrevAWSurfFlag1-PrevAWSurfFlag10)&lt;BR /&gt;
&lt;BR /&gt;
drop=var8 var26 var27 var42 var48 var59-var61 var212 var213 var219-var223 var237 var249 var250 var252-var255 var275 var376-var385 &lt;BR /&gt;
var706-var715 var826-var845 var1016-var1035 var1146 var1224-var1253 var1268-var1327 var1375-var1382 var1413-var1435);&lt;BR /&gt;
run;&lt;BR /&gt;
		data %substr(%sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.)),1,7);&lt;BR /&gt;
			set %sysfunc(translate(&amp;amp;&amp;amp;fname&amp;amp;i,_,.));&lt;BR /&gt;
		run;&lt;BR /&gt;
	%end;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend import;&lt;BR /&gt;
%import;

Message was edited by: Bryce</description>
      <pubDate>Mon, 09 Mar 2009 14:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76478#M16557</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-09T14:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76479#M16558</link>
      <description>One thing you want to change is the looping.  You want to read all the .1 files in a single data step that is what my example attemtents to demonstrate.  Then you can do similar for .2 and .DRF.  When these three steps are one you will have 3 SAS data sets that you can summarize as you see fit.&lt;BR /&gt;
&lt;BR /&gt;
I will work to make a more specifiy example.  Can you make some of the files available online somehow?&lt;BR /&gt;
&lt;BR /&gt;
Also if you can copy the PROC IMPORT generated data step code from a SAS log.  This will be the same code we need to put in the data step we write that reads all the file of type .1</description>
      <pubDate>Mon, 09 Mar 2009 15:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76479#M16558</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-09T15:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76480#M16559</link>
      <description>Wow!!!&lt;BR /&gt;
&lt;BR /&gt;
Where do I start with that?&lt;BR /&gt;
&lt;BR /&gt;
Firstly you will need to read the files using the infile and input statements like this:&lt;BR /&gt;
&lt;BR /&gt;
data yourdata;&lt;BR /&gt;
infile xxxxxx dsd;&lt;BR /&gt;
input variableA variableB etc etc&lt;BR /&gt;
&lt;BR /&gt;
I cant explain how all that works here I would point you in the direction of the SAS documentation.&lt;BR /&gt;
&lt;BR /&gt;
Secondly, use as few data steps as possible. Every time you put a set and data statment SAS has to read though every record in the data set which uses up resources. Do as much manipulation as you can in the one data step, ie the one you read the files in. SO do your deletes and renames and everything in there. DOing a data step simply to rename variables is a complete waste of resources and will slow you down. &lt;BR /&gt;
&lt;BR /&gt;
Only keep the variables you are interested in. If, as I can see in one of them, you are not interested in the last 10 variables, just don't bother reading them in from the file (I appreciate that import will do this anyway, but when you use the infile and input statement, just read in what you need).&lt;BR /&gt;
&lt;BR /&gt;
Also the amount of data in your _2005_ library will have no effect on how quickly it runs, you only need to worry about clearing that out if you are going to run out of space.&lt;BR /&gt;
&lt;BR /&gt;
As I say, the imperative thing is to keep your datasteps to a minimum. If you think of datasets as books. Each datastep is like going through every page. If you were going to sign your name of every page in a book and put a date at the top you wouldn't run through every page signing your name, then go back to the start and put the date of every page, you'd be much faster putting both the date and signature on each page at the same time. Hope that analogy isn't too absract.</description>
      <pubDate>Mon, 09 Mar 2009 15:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76480#M16559</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-09T15:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple files and merging into one database</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76481#M16560</link>
      <description>I wanted to walk through this, I am commenting it so maybe you can direct me in the things I do not understand.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
dm 'clear log; clear output;';&lt;BR /&gt;
* create test data(files to be read in next step);&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	length command $256;  *command will be the location of the files;&lt;BR /&gt;
	infile cards truncover;  *tells SAS to read through the cards later in the program;&lt;BR /&gt;
	input name :$128.;  *what it reads in will be called 'name'  What does the ':' do?&lt;BR /&gt;
	if _n_ eq 1 then do;&lt;BR /&gt;
		path = quote(substr(name,1,find(name,'\',-length(name))));  *define the path name;&lt;BR /&gt;
		command = 'rmdir /S /Q ".\xUsers\"';  *don't understand this step; &lt;BR /&gt;
		infile dummy1 pipe filevar=command;  *read all of the files located in the command location (or open a pipe to that location);&lt;BR /&gt;
		command=catx(' ','mkdir',path);  *creates this directory with the location designated in path;&lt;BR /&gt;
		put command=;&lt;BR /&gt;
		infile dummy1 pipe filevar=command; *pipe again to command location.  What exactly does filevar= do?;&lt;BR /&gt;
		rc = sleep(1);&lt;BR /&gt;
		end;&lt;BR /&gt;
	file dummy filevar=name dsd dlm=',';&lt;BR /&gt;
	do _n_ = 1 to 6;&lt;BR /&gt;
		put _n_:z5. name;&lt;BR /&gt;
		end;&lt;BR /&gt;
	cards;  *read the cards.  How do I get ALL the files I need here?;&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX05132005.1&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX05132005.2&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX0513.DRF&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX05142005.1&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX05142005.2&lt;BR /&gt;
	.\xUsers\mherrin\Documents\trial\APX0514.DRF&lt;BR /&gt;
	;;;;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*Read Type .1 (RACE) files;&lt;BR /&gt;
&lt;BR /&gt;
data type1;&lt;BR /&gt;
	length command filename fname path $256.;&lt;BR /&gt;
	command = 'dir /s /b ".\xUsers"';  *dir has not been defined how does this work?;&lt;BR /&gt;
	infile dummy1 pipe filevar=command truncover;&lt;BR /&gt;
	input path $256.;&lt;BR /&gt;
	if scan(path,-1,'.') eq '1';  *selects only the .1 files;&lt;BR /&gt;
	put _infile_;  *???;&lt;BR /&gt;
	infile dummy2 filevar=path filename=fname end=eof dsd;&lt;BR /&gt;
	filename = scan(fname,-2,'.\');  *fname does not exist in this data set at the end?;&lt;BR /&gt;
	length prefix $3.;&lt;BR /&gt;
	prefix = filename; *assumes prefix is always first 3 characters;&lt;BR /&gt;
	date = input (substr(filename,anydigit(filename)),mmddyy10.);&lt;BR /&gt;
	do while(not eof);&lt;BR /&gt;
		input obs name:$64.; ** Fields for type 1 files?;&lt;BR /&gt;
		output;&lt;BR /&gt;
		end;&lt;BR /&gt;
	format date date9.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
In the end I get a data file with the variables you defined; filename, prefix, date, ...  I know you wrote above to put in the field types for the data do I need to first declare them in the lenght statement above?  It does not seem to be reading any information from the file itself only the file name so far.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Mon, 09 Mar 2009 15:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-files-and-merging-into-one-database/m-p/76481#M16560</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-09T15:28:37Z</dc:date>
    </item>
  </channel>
</rss>

