Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Importing all text files within a directory into a  SAS program

Posted on 2011-09-26
3
Medium Priority
?
498 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
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…

715 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