Solved

Importing all text files within a directory into a  SAS program

Posted on 2011-09-26
3
436 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
Read about achieving the basic levels of HRIS security in the workplace.
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now