Solved

Importing all text files within a directory into a  SAS program

Posted on 2011-09-26
3
453 Views
Last Modified: 2013-11-16
I have a directory that has weekly files. All of the files begin with BCM.  They are in Directory BCM Weekly.  Is there a way to bring all of the files into my SA program concatenating them into one output dataset without listing them all individually?
0
Comment
Question by:morinia
3 Comments
 
LVL 14

Expert Comment

by:Aloysius Low
ID: 36644824
you can do so by concatenating the individual files into 1 file then load the data from the concatenated file into a sas dataset by executing this at the command prompt:
for windows:
type BCM* > [consolidated filename]

for unix:
more BCM* > [consolidated filename]

you'll need to be at the BCM Weekly directory to execute the commands...

the other way is to loop for all files in the directory - to read into a sas dataset and append into the final dataset, but personally i'll prefer the first as it loads only 1 file into 1 dataset
0
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 500 total points
ID: 36707667
Hi

An easy method is to just use wildcards in the filename statement:


FILENAME AllFiles 'c:\BCM Weekly\BCM*.txt';

DATA Test;
 infile AllFiles TRUNCOVER;
 INPUT txtrecd $256.;
RUN;
0
 

Author Comment

by:morinia
ID: 36707754
I am having a problem concatenating the files.  I am in Windows.  I created a bat file in the directory. I cannot get the command above to work at all.

The closest I get is usng the bat file below, but it puts everything on one line

@echo off
 
copy /b *.txt newfile.txt

I am trying to get the following files into one


A 111         -------->   BCM1.txt
B  222       ---------->  BMC2.txt
C 333        ---------->  BCM3.txt
D 444         ----------> BCM4.txt
E 555         ----------> BCM5.txt

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question