BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saket_90
Calcite | Level 5

Hi,

 

I am trying to load the data from multiple text files palced in a folder having the same structure to one file. All the text files are having the same headers.

Sample data in one of the file:

Product                       Customer    Qtr 1     Qtr 2         Qtr 3         Qtr 4
Alice_Mutton               ANTON     28080     70200      110400      55125
Aniseed_Syrup            BERGS     31200     78000      60000       14700
Boston_Crab               BOLID       28080     6000        77280      117000
Escargots_Bourgogne BOTTM    117000    20000     16560       122360
Filo_Mix                       ERNSH     112320   18000      92000       260715
Geitost                         GODOS    6240       28080      24840       41952

 

Also the names of the file are cust101, cust102, cust103.........Cust200...

 

Can anyone please suggest an efficient way to read the data from all these text file in to a single file.

 

Regards,

Saket

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's my recommended solution:

 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 

1. You need your input/informat/format statement for reading a single file.

2. In the code in link above, change the path, and use a wildcard to reference the data.

3. Make sure to use the EOV= variable to avoid reading the header in each file.

 

View solution in original post

3 REPLIES 3
Pamela_JSRCC
Quartz | Level 8

You can read multiple files using wildcrds. The code below is not tested but should help get you started.

 

%let data_filepath = c:\...\cust*;  * modify path as appropriate for your system;

 

data temp;
infile firstobs=2 "&data_filepath";
input product $ customer $ qtr1-qtr4;
run;

Reeza
Super User

Here's my recommended solution:

 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 

1. You need your input/informat/format statement for reading a single file.

2. In the code in link above, change the path, and use a wildcard to reference the data.

3. Make sure to use the EOV= variable to avoid reading the header in each file.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 5383 views
  • 3 likes
  • 4 in conversation