Date: Thu, 28 Aug 2008 13:31:50 +0100
Reply-To: "Wilson, Jared" <Jared.Wilson@RSPB.ORG.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Wilson, Jared" <Jared.Wilson@RSPB.ORG.UK>
Subject: multiple file import, datetime format etc.
Content-Type: text/plain; charset="us-ascii"
Hi all ,
I am wanting to import multiple text files into a single data file. All
of the tab delineated txt files (to date) have the same format, column
headings, etc and look like this:
Time Date Pressure
12:26:30 22.01.2008 0.193
12:41:30 22.01.2008 0.193
12:56:30 22.01.2008 0.192
13:11:30 22.01.2008 0.192
13:26:30 22.01.2008 0.192
13:41:30 22.01.2008 0.191
13:56:30 22.01.2008 0.191
14:11:30 22.01.2008 0.191
14:26:30 22.01.2008 0.191
I'm using the Macro in SUGI 29
http://www2.sas.com/proceedings/sugi29/057-29.pdf
<http://www2.sas.com/proceedings/sugi29/057-29.pdf> - see below. When
I run the macro the var_names file has the 3 variable names all in the
X1 column with columns X2 and X3 blank. Is there any reason why this
should be? Do I need to specify tab delineation if this is the issue ?.
Also, I am assuming that I am going to run into problems with importing
the Time and Date formats. I've read up all I can find online etc about
this and am totally confused about how I can resolve any issues that may
be present with the code below.
Any help would be great- have spent a very long time trying to sort this
out and have failed.
cheers
jared
filename indata pipe 'dir
D:\LIFE\F02F03Monitoring\SAS\ImporttoSAS\allTAGtxt /b';
data file_list;
length fname $20;
infile indata truncover; /* infile statement for file names */
input fname $20.; /* read the file names from the directory */
call symput ('num_files',_n_); /* store the record number in a macro
variable */
run;
%macro fileread;
%do j=1 %to &num_files;
data _null_;
set file_list;
if _n_=&j;
call symput ('filein',fname);
run;
data var_names;
length x1-x3 $12;
infile "D:\LIFE\F02F03Monitoring\SAS\ImporttoSAS\allTAGtxt\&filein"
obs=1 missover;
input (x1-x3) ($) ;
run;
%macro varnames;
%do i=1 %to 3;
%global v&i;
data _null_;
set var_names;
call symput("v&i",trim(x&i));
run;
%end;
%mend varnames;
%varnames;
data temp;
infile "D:\LIFE\F02F03Monitoring\SAS\ImporttoSAS\allTAGtxt\&filein"
firstobs=2 missover;
input (&v1 &v2 &v3) ($);
run;
%if &j=1 %then %do;
data data_all;
set temp;
run;
%end;
%else %do;
data data_all;
set data_all
temp;
run;
%end;
%end; /* end of do-loop with index j */
%mend fileread;
%fileread;