Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importing all text files within a directory into a  SAS program

Posted on 2011-09-26
3
Medium Priority
?
505 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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