Solved

Importing all text files within a directory into a  SAS program

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
constraint check 2 55
MIcrosoft SQL 2014 Database Copy Question 16 59
Access 2016 Query with Proper Case logic 2 48
subtr returning incorrect value 8 63
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
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…

735 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